如何使用 numpy 和 random 将随机生成的数组值拆分为两个单独的数组?

How to split random generated array values in two separate array using numpy and random?

如何创建一个名为 row_min 的向量,其中包含 25 行中每一行的最小值(这意味着该向量的形状将为 (25,)) 创建一个名为 [=18= 的向量] 包含 8 列中每一列的最大值(col_max 将是形状为 (8,) 的向量)

我已经开发了代码,我对矢量概念还不熟悉,需要一些建议。

import random
import numpy

c = numpy.random.rand(25,8)
print("Random float array 25X8 between range of 0.0 to 1.0 \n")
print(c,"\n")

我没有找到理解这个概念的来源。

您必须指定 np.max( .., axis=...) 应该在:

import random
import numpy as np

c = np.random.rand(5,3) # smaller for less output 
print(c,"\n")

print( np.max(c, axis=0)) # column
print( np.max(c, axis=1)) # row

输出:

[[0.47894278 0.80356294 0.34453725]
 [0.33802491 0.82795648 0.28438504]
 [0.46838701 0.73664987 0.82215448]
 [0.66245476 0.59981989 0.43837083]
 [0.28515865 0.86093323 0.92248524]] 

# axis 0 (columns)
[0.66245476 0.86093323 0.92248524]
# axis 1 (rows)
[0.80356294 0.82795648 0.82215448 0.66245476 0.92248524]

参见 matrix.max() ... min() 效果相同。