indexing

getting indices when comparing multidimensional arrays

萝らか妹 提交于 2019-12-25 03:53:47
问题 I have two numpy arrays, one an RGB image, one a lookup table of pixel values, for example: img = np.random.randint(0, 9 , (3, 3, 3)) lut = np.random.randint(0, 9, (1,3,3)) What I'd like is to know the x,y coordinate in lut of pixels whose values are common to img and lut , so I tried: for x in xrange(img.shape[0]): for y in xrange(img.shape[1]): print np.transpose(np.concatenate(np.where(lut == img[x,y]))) At this point, the problem is that img[x,y] , which will be in the form of [int_r, int

Removing duplicates from MySQL on a column that's too big to INDEX

大城市里の小女人 提交于 2019-12-25 03:44:19
问题 I'm trying to remove duplicate rows from a table with millions of rows. The field I want to check for duplicates on is too long (it's storing URLs) to put a UNIQUE index on. Is there any way to remove duplicates quickly? The recommended method for removing duplicates: DELETE t1 FROM table1 AS t1 JOIN table1 AS t2 ON t1.id>t2.id AND t1.name=t2.name; Never seems to finish its job, though I suppose it might just require a lot of time to do. One idea I've heard here is to create an MD5 hash

In R, why does deleting rows or cols by empty index results in empty data ? Or, what's the 'right' way to delete?

元气小坏坏 提交于 2019-12-25 03:22:16
问题 This is one of the things that really annoys me in R. Consider the following example: a=data.frame(x=c(1,2),y=c(3,4)) i=which(a$x==0) At this point, i is "integer(0)" and length(i) is 0. Now if I do: b=a[-i,] Because I'm deleting by an empty index, I expect b to have all the data in a. But instead b is an empty data frame. I have to do this instead: if (length(i)>0) b=a[-i,] else b=a The same applies to matrices too. Is there a way to delete that handles empty index correctly without the if

How to Index subjects using R [duplicate]

做~自己de王妃 提交于 2019-12-25 03:21:32
问题 This question already has answers here : Numbering rows within groups in a data frame (6 answers) Closed 4 years ago . I am working in R and I have a Data set that has multiple entries for each subject. I want to create an index variable that indexes by subject. For example: Subject Index 1 A 1 2 A 2 3 B 1 4 C 1 5 C 2 6 C 3 7 D 1 8 D 2 9 E 1 The first A entry is indexed as 1, while the second A entry is indexed as 2. The first B entry is indexed as 1, etc. Any help would be excellent! 回答1:

Julia redefining indices when accessing an array

浪子不回头ぞ 提交于 2019-12-25 03:20:55
问题 I have a structure implementing the Array interface. I want to redefine the indices when accessing it. So far, I did it in the Base.getindex function for my type, but I have seen the Base.to_indices function in the doc and do not know how they work together. It is possible to access array elements using : ( Colon ), UnitRange , StepRange , OneTo , Int or Int arrays , so where should I redefine the indices without having to manage all these cases? 回答1: It's hard to talk about this in the

Most efficient way to get indexposition of a sublist in a nested list

好久不见. 提交于 2019-12-25 03:16:40
问题 I want to get the indexposition of a sublist in a nested list, e.g 0 for [1,2] in nested_ls = [[1,2],[3,4]]. What's the most elegant way of getting the index of the sublist, is there something similar to index() ? 回答1: Yes. It's called index . >>> [[1, 2], [3, 4]].index([1, 2]) 0 >>> [[1, 2], [3, 4]].index([3, 4]) 1 >>> [[1, 2], [3, 4]].index([1, 5]) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: [1, 5] is not in list 来源: https://stackoverflow.com/questions

Is there an efficient way to index inside words in SQL server 2008?

跟風遠走 提交于 2019-12-25 03:15:14
问题 We have a a few queries in our system that use LIKE '%'+@SomeCriteria+'%' to search a for a person's name. We are talking VARCHAR(50) fields in this case. We would really like to allow our users the ability to search within names. The way I understand it, indexing the field will only make this faster if we search for the first part of the name, and full text indexing will search for specific words, but as far as I can tell doesn't help when searching within words. Is there a good way in SQL

More LValue Errors

那年仲夏 提交于 2019-12-25 03:08:45
问题 Below is a triple nested indexing scheme. My pointer to an array of pointers is dereferenced on the commented line... in theory this should give me a pointer. I subtract one from it and then reference it and reassign that to my pointer to the array of pointers. But that line gives an lvalue error for the operand "&". Let me be perfectly clear. I want to both know why the error is occurring here AND get a method that works for assigning the address of the previous element in the array of

“list index out of range” when try to output lines from a text file using python

╄→尐↘猪︶ㄣ 提交于 2019-12-25 02:59:08
问题 I was trying to extract even lines from a text file and output to a new file. But with my codes python warns me "list index out of range". Anyone can help me? THANKS~ Code: f = open('input.txt', 'r') i = 0 j = 0 num_lines = sum(1 for line in f) newline = [0] * num_lines print (num_lines) for i in range(1, num_lines): if i % 2 == 0: newline[i] = f.readlines()[i] print i, newline[i] i = i + 1 f.close() f = open('output.txt', 'w') for j in range(0,num_lines): if j % 2 == 0: f.write(newline[j] +