where

Numpy Where Changing Timestamps/Datetime to Integers

Numpy Where Changing Timestamps/Datetime to Integers Question: Not so much a question but something puzzling me. I have a column of dates that looks something like this: 0 NaT 1 1996-04-01 2 2000-03-01 3 NaT 4 NaT 5 NaT 6 NaT 7 NaT 8 NaT I’d like to convert it the NaTs to a static …

Total answers: 3

Conditional Replace within a Column of a Numpy Array

Conditional Replace within a Column of a Numpy Array Question: I have a numpy array, for example: theData= [[0, 1, 1, 1],[0, 1, 3, 1],[3, 4, 1, 3],[0, 1, 2, 0],[2, 1, 0, 0]] How do I replace all the zeros in the first column with -1? It’s easy to replace all the zeros in …

Total answers: 4

Find index mapping between two numpy arrays

Find index mapping between two numpy arrays Question: Is there a nice way in numpy to get element-wise indexes of where each element in array1 is in array2? An example: array1 = np.array([1, 3, 4]) array2 = np.arange(-2, 5, 1, dtype=np.int) np.where(array1[0] == array2) # (array([3]),) np.where(array1[1] == array2) # (array([5]),) np.where(array1[2] == array2) # …

Total answers: 2

How can you turn an index array into a mask array in Numpy?

How can you turn an index array into a mask array in Numpy? Question: Is it possible to convert an array of indices to an array of ones and zeros, given the range? i.e. [2,3] -> [0, 0, 1, 1, 0], in range of 5 I’m trying to automate something like this: >>> index_array = …

Total answers: 4

How to use numpy.where with logical operators

How to use numpy.where with logical operators Question: I’m trying to find the indices of all elements in an array that are greater than a but less than b. It’s probably just a problem with my syntax but this doesn’t work: numpy.where((my_array > a) and (my_array < b)) How should I fix this? Or is …

Total answers: 1