any

Python: any() unexpected performance

拜拜、爱过 提交于 2019-12-07 04:51:30
问题 I am comparing the performance of the any() built-in function with the actual implementation the docs suggest: I am looking for an element greater than 0 in the following list: lst = [0 for _ in range(1000000)] + [1] This is the supposedly equivalent function: def gt_0(lst): for elm in lst: if elm > 0: return True return False And these are the results of the performance tests: >> %timeit any(elm > 0 for elm in lst) >> 10 loops, best of 3: 35.9 ms per loop >> %timeit gt_0(lst) >> 100 loops,

Why does Typescript allow to assign an “any” object type to class object?

邮差的信 提交于 2019-12-07 03:50:32
问题 I have a class object: groupNameData: GroupNameData = new GroupNameData(); and I have an any object groupNameDatas: any; Assignment 1 (class = any) I just assigned the class object values to any object, like this.groupNameDatas = this.groupNameData; It means, this.groupNameDatas (Any) can accept any kind of data, because it's an any object. Assignment 2 (any = class) Now I have reversed the assignment, like this.groupNameData = this.groupNameDatas;// any to class It's also working like my

How to check if any value of a column is in a range (in between two values) in Pandas?

心不动则不痛 提交于 2019-12-07 01:36:53
问题 I have a DataFrame and I would like to check if any of the values (v) of a column satisfies x<=v<=y . equal = any(df['columnX'] == value) # No problems here in_between = any(x <= df['columnX'] <= y) # ValueError :/ The error I get is ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). But I am using any() already! So what's the problem here? Why does it work with == but not with x<=v<=y ? 回答1: Use between to do this, it also supports

How to use numpy.all() or numpy.any()?

丶灬走出姿态 提交于 2019-12-06 05:02:06
I am trying to search in a 2D numpy array for a specific value, the get_above method returns a list of coordinates above the character 'initial char' def get_above(current, wordsearch): list_of_current_coords = get_coords_current(current, wordsearch) #print(list_of_current_coords) length = len(list_of_current_coords) first_coords = [] second_coords = [] for x in range(length): second = list_of_current_coords[x][1] new_first = list_of_current_coords[x][0] - 1 first_coords.append(new_first) second_coords.append(second) combined = [first_coords, second_coords] above_coords = [] for y in range

Compare Boolean Row values across multiple Columns in Pandas using & / np.where() / np.any()

十年热恋 提交于 2019-12-06 04:08:00
I have a dataframe that looks like: a A a B a C a D a E a F p A p B p C p D p E p F 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 2 0 1 0 0 0 0 0 0 1 0 0 0 3 0 0 1 0 0 1 0 0 0 0 0 0 4 0 0 0 1 0 1 0 0 0 0 0 0 5 0 0 0 0 1 0 0 0 0 0 0 0 6 0 0 0 0 0 0 1 0 0 0 0 0 df = pd.DataFrame({'p A':[0,0,0,0,0,0,1],'p B':[0,0,0,0,0,0,0],'p C':[0,0,1,0,0,0,0],'p D':[0,0,0,0,0,0,0],'p E':[0,0,0,0,0,0,0],'p F':[0,0,0,0,0,0,0],'a A':[0,1,0,0,0,0,0],'a B':[0,0,1,0,0,0,0],'a C':[0,0,0,1,0,0,0],'a D':[0,0,0,0,1,0,0],'a E':[0,0,0,0,0,1,0],'a F': [0,0,0,1,1,0,0]}) Note: This is a much simplified version of my

SQL - Find the grade of students who only like students in the same grade

前提是你 提交于 2019-12-05 14:04:14
I am doind a free Stanford online course (which is pretty cool, you should check that out) and I've been racking my brains for the lest 2 days and can't find an answer to the following problem. Please help. Question 4 Find names and grades of students who only have friends in the same grade. Return the result sorted by grade, then by name within each grade. When I finally thought that I had the answer my query returned all the values from the table Friend. This is the best I could come up with. select h1.id, h1.name, h1.grade, h2.id, h2.name, h2.grade from friend f1 join highschooler h1 on f1

What is the difference between any and any[ ]?

心已入冬 提交于 2019-12-05 13:10:15
问题 What is the difference between any and any[ ]? Example 1 (working as expected) name1: any; name2: any[]; this.name1 = this.name2; Example 2 (This is also working as expected) name1: any; name2: any[]; this.name2 = this.name1; Why typescript allowing any data type can be access any[] data type. As same as any[] data type can be access any type of data? and Which one is best to use? And If the data type is just an object (not an array) like string or number or object or any , then why any[ ]

Python: any() unexpected performance

独自空忆成欢 提交于 2019-12-05 12:25:55
I am comparing the performance of the any() built-in function with the actual implementation the docs suggest: I am looking for an element greater than 0 in the following list: lst = [0 for _ in range(1000000)] + [1] This is the supposedly equivalent function: def gt_0(lst): for elm in lst: if elm > 0: return True return False And these are the results of the performance tests: >> %timeit any(elm > 0 for elm in lst) >> 10 loops, best of 3: 35.9 ms per loop >> %timeit gt_0(lst) >> 100 loops, best of 3: 16 ms per loop I would expect both of the to have the exact same performance, however any()

Why does Typescript allow to assign an “any” object type to class object?

会有一股神秘感。 提交于 2019-12-05 07:59:12
I have a class object: groupNameData: GroupNameData = new GroupNameData(); and I have an any object groupNameDatas: any; Assignment 1 (class = any) I just assigned the class object values to any object, like this.groupNameDatas = this.groupNameData; It means, this.groupNameDatas (Any) can accept any kind of data, because it's an any object. Assignment 2 (any = class) Now I have reversed the assignment, like this.groupNameData = this.groupNameDatas;// any to class It's also working like my first assignment example. Why it did not throw an error like cannot convert implicitly "any" to

How to check if any value of a column is in a range (in between two values) in Pandas?

安稳与你 提交于 2019-12-05 06:03:34
I have a DataFrame and I would like to check if any of the values (v) of a column satisfies x<=v<=y . equal = any(df['columnX'] == value) # No problems here in_between = any(x <= df['columnX'] <= y) # ValueError :/ The error I get is ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). But I am using any() already! So what's the problem here? Why does it work with == but not with x<=v<=y ? Use between to do this, it also supports whether the range values are included or not via inclusive arg: In [130]: s = pd.Series(np.random.randn(5)) s