python 求数组极值,均值 和范数 2021-11-05

python 求数组极值,均值 和范数

import numpy as np
import numpy as rd
arr = rd.randiant(1,100,size= (10,10),dtype ='uint8')
np.savetxt('test.txt",arr,"%d")

arr1 = np.loadtxt("test.txt",int)
max1 = np.max(arr1)
max2 = np.min(arr1)
mean1 = np.mean(arr1)
sum1 = np.sum(arr1)

求某一维度上的特征

求每行的最大值已经对应的小标

row_max = np.max(arr1,axis = 1)
row_max_idx = np.argmax(arr1,axis = 1)

求每列的最小值以及对应的下标

col_min = np.min(arr1,axis = 0)
col_min_idx = np.argmin(arr1,axis = 0)

求每一维度(axis = 0) 的一范数(ord = 1)

效果和对应数组按列求和一样

norm1 = np.linalg.norm(arr1,axis = 0, ord = 1)

求第二维度(axis = 1)的二范数 (ord = 2)

norm2 = np.linalg.norm(arr1,axis = 1, ord = 2)

范数.PNG

你可能感兴趣的:(python 求数组极值,均值 和范数 2021-11-05)