I created two 3D array like this
import numpy as np
np.random.seed(1)
prices = np.random.randint(10, 20, size = (2, 2, 2)
#prices -> [[[19 10] [[19, 19]
# [14 17]], [19, 16]]]
clients = []
for i in range (3):
if i == 0:
clients.append(np.random.randint(1, 10, size = (2,2)))
elif i == 1:
clients.append(np.random.randint(11, 20, size = (2, 2)))
elif i == 2:
clients.append(np.random.randint(21, 30, size = (2, 2)))
z = np.array(clients)
# z -> [[[ 8 3] [[14, 19] [[21 26]
# [ 2 6]] [16, 15]] [21 25]]]
and after that I was able to concatenate both arrays like this
concatenate = []
for i in prices:
for j in z:
concatenate.append(np.concatenate((i,j), axis = 1))
prices2 = np.array(concatenate)
# prices2 ->[[[19 10 8 3] [[19 10 14 19] [[19 10 21 26] [[19 19 8 3] [[19 19 14 19] [[19 19 21 26]
# [14 17 2 6]] [14 17 16 15]] [14 17 21 25]] [19 16 2 6]] [19 16 16 15]] [19 16 21 25]]]
What I want is to sort this 3D array in ascending order using the information in the third column of each 2D array, for example:
# new = [[[19 10 8 3] [[19 19 8 3] [[19 10 14 19] [[19 19 14 19] [[19 10 21 26] [[19 19 21 26]
# [14 17 2 6]] [19 16 2 6]] [14 17 16 15]] [19 16 16 15]] [14 17 21 25]] [19 16 21 25]]]
#Here 8 < 14 < 21
# 2 < 16 < 21
I know numpy has a function called np.sort
but many examples I see uses 2D arrays instead of 3D arrays, and I don't really know how to do this.