排序:按照最后一个维度进行排序,最后一个维度相同的随机排列
import numpy as np
a=np.array([[[3,4,3],[2,1,7],[2,3,4],[1,6,4]],[[3,4,2],[1,5,0],[2,0,0],[5,6,0]],[[3,4,5],[2,3,0],[2,7,0],[5,6,float("inf")]]])
print(a)
rng = np.random.default_rng()
a = rng.permutation(a,axis=1)
print(f'a[:,:,-2]: {a[:,:,-2]}')
tmp = [a[0,np.argsort(a[:,:,-1])[0],:]]
for i in range(1,a.shape[0]):
#tmp = np.concatenate((tmp, [a[i, np.lexsort((a[:,:,-2], a[:,:,-1]))[i], :]]))
tmp = np.concatenate((tmp, [a[i, np.argsort(a[:,:,-1])[i], :]]))
print(f'tmp:{tmp}')
拆分:中间参数是[x,x,x...]的array,数组中的数作为index进行指定分割
def split(ary, indices_or_sections, axis=0):
"""
Split an array into multiple sub-arrays as views into `ary`.
Parameters
----------
ary : ndarray
Array to be divided into sub-arrays.
indices_or_sections : int or 1-D array
If `indices_or_sections` is an integer, N, the array will be divided
into N equal arrays along `axis`. If such a split is not possible,
an error is raised.
If `indices_or_sections` is a 1-D array of sorted integers, the entries
indicate where along `axis` the array is split. For example,
``[2, 3]`` would, for ``axis=0``, result in
- ary[:2]
- ary[2:3]
- ary[3:]
If an index exceeds the dimension of the array along `axis`,
an empty sub-array is returned correspondingly.
axis : int, optional
The axis along which to split, default is 0.
Returns