注:只能使用np.where
import numpy as np
a = np.array([[1,3,6],[9,3,2],[1,4,3]])
print(f'数组:\n{a}')
print("-"*30)
print(np.where(a>3,520,1314)) #只能使用np.where
any:检查一个数组中是否有any
all:检查数组中是否每个值都为true
import numpy as np
a = np.array([False,True,False])
print(f'数组:\n{a}')
print("-"*30)
print(a.all())
print("-"*30)
print(a.any())
import numpy as np
a = np.array([1,3,6,4,9])
print(f'数组:\n{a}')
print("-"*30)
print(np.sort(a))
import numpy as np
a = np.array([[1,3,6],[9,3,2],[1,4,3]])
print(f'数组:\n{a}')
print("-"*30)
print(np.sort(a)) # 按照最后的轴排序 (行,列) 按照列排序
print("-"*30)
print(np.sort(a,axis=0))#按照行排序
import numpy as np
a = np.array([1,9,6])
print(f'数组:\n{a}')
print("-"*30)
print(np.argsort(a))#升序
print("-"*30)
print(np.argsort(-a)) #降序
import numpy as np
a = np.array([[1,3,6],[9,3,2],[1,4,3]])
print(f'数组:\n{a}')
print("-"*30)
print(np.argsort(a))
print("-"*30)
print(np.argsort(a,axis=0))
import numpy as np
a = np.array([[1,3,6],[9,3,2],[1,4,3]])
print(f'数组:\n{a}')
print("-"*30)
print(np.unique(a))
import numpy as np
a = np.array([[1,3,6],[9,3,2],[1,4,3]])
print(f'数组:\n{a}')
print("-"*30)
print(np.in1d(a,[1,3,6]))