下面的代码计算平均行数,并从矩阵行数中减去。我将my_vector转换为矩阵进行计算。
import numpy as np
my_vector = ([3, 6, 5, 4, 2],
[2, 3, 4, 5, 6],
[4, 3, 2, 1, 5],
[5, 3, 1, 3, 4])
my_matrix = np.array(my_vector)
#print(my_matrix)
mrow = np.mean(my_matrix,axis=1) #row mean
mrow = np.round(mrow)
print(mrow)
#print(my_matrix.shape[0])
d_meaned = my_matrix.copy()
for i in range(my_matrix.shape[0]):
d_meaned[i] = d_meaned[i]-mrow[i]
print(d_meaned)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句