Rank items in an array using Python/NumPy, without sorting array twice
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have an array of numbers and I'd like to create another array that represents the rank of each item in the first array. I'm using Python and NumPy. , Use slicing on the left-hand side in the last step: array = numpy.array([4,2,7,1])
temp = array.argsort()
ranks = numpy.empty_like(temp)
ranks[temp] = numpy.arange(len(array))
|
numpy not sorting simple numpy array with duplicate items
Date : March 29 2020, 07:55 AM
Does that help The np.sort function is not in place, it returns an array. To sort in place you must use the array.sort method : my_symbols.sort().
|
Sorting array with numpy
Date : March 29 2020, 07:55 AM
this one helps. You need numpy.lexsort, which is equivalent to argsort but based on multiple sorting keys; Given multiple arrays, it returns the index to sort the arrays in an order: a[:, np.lexsort(a[:0:-1])]
#array([[2, 1, 3, 2, 3, 2, 1, 4, 0, 4, 3, 2, 4, 4, 4, 4],
# [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
# [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]])
|
Re-Sorting 3D-Numpy Array
Date : March 29 2020, 07:55 AM
will be helpful for those in need numpy.transpose(..) is a function that can permutate the axes in any order. If I understood it correctly, you basically want the third and fourth axis to be the first and second axis of the new matrix, and the old first and second matrix to be the new third and fourth axis. >>> a.transpose((2,3,0,1))
array([[[[9, 9, 9, 3]],
[[6, 1, 2, 7]],
[[1, 9, 7, 0]]],
[[[2, 6, 6, 4]],
[[8, 6, 1, 0]],
[[6, 7, 4, 6]]],
[[[3, 3, 9, 7]],
[[5, 0, 2, 4]],
[[6, 7, 2, 8]]]])
>>> a[0,:,:,:].transpose(1,2,0)
array([[[9, 9, 9, 3],
[6, 1, 2, 7],
[1, 9, 7, 0]],
[[2, 6, 6, 4],
[8, 6, 1, 0],
[6, 7, 4, 6]],
[[3, 3, 9, 7],
[5, 0, 2, 4],
[6, 7, 2, 8]]])
|
My code has created a numpy array inside another numpy array for one list but it does not for another list that goes thr
Tag : python , By : Picoman Games
Date : March 29 2020, 07:55 AM
Hope that helps I'm developing a simple Artificial Intelligence for a college project and so far it has worked until it randomly began creating a numpy array inside another numpy array. One of the lists that are being converted is a dataset that I've created myself that then is iterated through and each image is read by cv2 and added to a new list. This new list is then converted into a numpy array (this is the one that causes the problem). A second, smaller list (test images) goes through the same process and comes out with the desired result. , The problem is in for i in range (0, len(images)):
img = cv2.imread(images[i])
readyImages.append(img)
|