我对numpy和python一般都是新手,我希望找到每个二维子数组的最小值,给定一个三维数组。例如:
# construct an example 3D array
a = np.array([[5,4,1,5], [0,1,2,3], [3,2,8,1]]).astype(np.float32)
b = np.array([[3,2,9,3], [8,6,5,3], [6,7,2,8]]).astype(np.float32)
c = np.array([[9,7,6,5], [4,7,6,3], [1,2,3,4]]).astype(np.float32)
d = np.array([[5
如果我有一个数组并应用求和 arr = np.array([[1.,1.,2.],[2.,3.,4.],[4.,5.,6]])
np.sum(arr,axis=1) 我得到了三行(4.,9.,15)的总和。 我的复杂之处在于,arr包含的数据在某个列索引之后可能是错误的。我有一个整数数组,它告诉我每行有多少个“好”值,我想对这些好值求和/求平均值。可以这样说: ngoodcols=np.array([0,1,2])
np.sum(arr[:,0:ngoodcols],axis=1) # not legit but this is the idea 很清楚如何在循环中做到这一点,但是有没有一