conditional-statements

Understanding the use of any() and all() in numpy arrays

喜你入骨 提交于 2021-01-28 09:38:19
问题 What's the difference between the following: a = np.array([2,3,4]) b = np.array([2,7,8]) if a.any() == b.all(): print('yes') and a = np.array([2,3,4]) b = np.array([2,7,8]) if a.any() == b.any(): print('yes') In both situations, 'yes' is printed. 回答1: any() and all() are intended for boolean arrays. any() returns True if there's any values that are equal to True in the array. all() returns True if all values in the array are equal to True . For integers/floats the functionality is similar,

How can I have a conditional statement that performs two tasks? first one and then the other in a loop

怎甘沉沦 提交于 2021-01-28 09:01:06
问题 So I am trying to code a program in arduino that does a task for 2 minutes and then another task for 5 mins. first one and then the other in a loop until a different condition is met. Ive been trying to do this with if statements and while loops but im getting lost in the time part i think //Pneumatic feed system double minute = 1000*60; double vibTime = 2 * minute; //2 mins //double vibTime = 5000; double execTime = millis(); double waitTime = 5 * minute; //time waits between vibrating /

How to check if Pandas rows contain any full string or substring of a list?

无人久伴 提交于 2021-01-28 04:51:30
问题 I have a list of strings list_ = ['abc', 'def', 'xyz'] And I have a df with column CheckCol , that I want to check if the values in CheckCol contains any of the whole of substring of the list element. If it does, I want to extract the original value into a new column NewCol . CheckCol 'a' 'ab' 'abc' 'abc-de' Into # What I want CheckCol NewCol 'a' 'ab' 'abc' 'abc' 'abc-de' 'abc-de' My following codes, however, only recognize the exact full string, but not the substrings I was looking for. df[

Conditionnal styles for cytoscape.js graph

℡╲_俬逩灬. 提交于 2021-01-28 02:46:30
问题 I want to change the style of my graph according to global Javascript variables. For exemple, assumung my edges got name and price attributes, I would like to make the labels of edges different, depending on a global label_type variable : let lable_type = 'I_want_name_labels' switch(lable_type) { case 'I_want_name_labels': cy.style().selector('edge').style({'label': 'data(name)'}); break; case 'I_want_price_labels': cy.style().selector('edge').style({'label': 'data(price)'}); break; } The

removing the first 3 rows of a group with conditional statement in r

喜夏-厌秋 提交于 2021-01-27 19:10:35
问题 I would like to remove rows that are not fulfilling the condition that I want. For example: Event Value 1 1 1 0 1 0 1 0 2 8 2 7 2 1 2 0 2 0 2 0 3 8 3 0 3 0 3 0 3 0 If per event, in the column of value there is a number higher than 2 (Value > 2) remove the first 3 rows starting from that Value that is not fulfilling the criteria. It should look like this: Event Value 1 1 1 0 1 0 1 0 2 0 2 0 3 0 3 0 I have been able to remove the first row of each Event that accomplish the criteria, but haven't

Filter rows which has at least one of particular values

时光总嘲笑我的痴心妄想 提交于 2021-01-27 16:41:37
问题 I have a data frame like this. df Tour Order Machine Company [1] A D D B [2] B B A G [3] A E B A [4] C B C B [5] A G G C I want to get the rows where the three columns Tour , Order Machine contains at least one D E or G . The result should be: Tour Order Machine Company [1] A D D B [3] A E B A [5] A G G C My attempt: df %>% filter(any(c(Tour, Order, Machine) %in% c('D', 'E', 'G'))) But it doesn't filter correctly(all the rows are returned). Could anybody please help me? 回答1: Another option:

Can I use a nested for loop for an if-else statement with multiple conditions in python?

我只是一个虾纸丫 提交于 2021-01-27 13:04:09
问题 I have written a program that checks if a chess board is valid. In one part of my code I test, if the amounts of the pieces are correct. count is dictionary, which is an inventory of the board I want to check. For example (b stands for black, w fo white): count = {'bking': 1, 'wking': 1, 'bpawn': 3, 'bbishop': 1, 'wrook': 1, 'wqueen': 1} the possible colors and pieces are available in lists: colors = ['b', 'w'] pieces = ['queen', 'rook', 'knight', 'bishop', 'pawn'] I have the following ugly

Scope Order by Count with Conditions Rails

穿精又带淫゛_ 提交于 2021-01-27 12:27:46
问题 I have a model Category that has_many Pendencies . I would like to create a scope that order the categories by the amount of Pendencies that has active = true without excluding active = false . What I have so far is: scope :order_by_pendencies, -> { left_joins(:pendencies).group(:id).order('COUNT(pendencies.id) DESC')} This will order it by number of pendencies, but I want to order by pendencies that has active = true . Another try was: scope :order_by_pendencies, -> { left_joins(:pendencies)

Pandas - check if a value exists in multiple columns for each row

北城以北 提交于 2021-01-24 11:41:40
问题 I have the following Pandas dataframe: Index Name ID1 ID2 ID3 1 A Y Y Y 2 B Y Y 3 B Y 4 C Y I wish to add a new column 'Multiple' to indicate those rows where there is a value Y in more than one of the columns ID1, ID2, and ID3. Index Name ID1 ID2 ID3 Multiple 1 A Y Y Y Y 2 B Y Y Y 3 B Y N 4 C Y N I'd normally use np.where or np.select e.g.: df['multiple'] = np.where(<More than 1 of ID1, ID2 or ID3 have a Y in>), 'Y', 'N') but I can't figure out how to write the conditional. There might be a

Google sheets automatic Notes [with onEdit() function] on cells' values resulting from formulas

我的未来我决定 提交于 2021-01-24 09:50:27
问题 Is it possible to create automatic Notes based on cells variable values resulting from formulas ? For example A1=stxt(B1;1;4) gives "some" with B1=sometext (variable value), so that A1's Note would be "some" And a second question : how to add at least a third condition for exceptions treatment in mySelection.getValues().flat().map(v=>[v=="/" || ""?null:v]); // or #N/A or #VALUE! I didn't neither succeed having many OR conditions in one single code line so that I have to put many if statements