Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在numpy数组中组合值_Python_Arrays_Numpy - Fatal编程技术网

Python 在numpy数组中组合值

Python 在numpy数组中组合值,python,arrays,numpy,Python,Arrays,Numpy,我有一些大小相同的MxN(SVM)的numpy阵列。我需要创建一个大小相同但每个位置值较高的新位置。例如: [[1,2,1,3], [[2,1,5,1], [[2,2,5,3], [2,5,2,1]] and [1,3,5,5]] result [2,5,5,5]] [4,1,3,1]] [4,2,1,2]] [4,2,3,2]] 总和和乘积如下:predict=a*b*c,其中a、b和c是从其他pre

我有一些大小相同的MxN(SVM)的numpy阵列。我需要创建一个大小相同但每个位置值较高的新位置。例如:

[[1,2,1,3],         [[2,1,5,1],          [[2,2,5,3],
 [2,5,2,1]]   and   [1,3,5,5]]   result   [2,5,5,5]]
 [4,1,3,1]]         [4,2,1,2]]            [4,2,3,2]]
总和和乘积如下:
predict=a*b*c
,其中
a、b和c
是从其他predict读取的大小相同的numpy数组

谢谢。

您可以在第0轴上使用
np.max()

>>> np.max((a,b), axis=0)
array([[2, 2, 5, 3],
       [2, 5, 5, 5],
       [4, 2, 3, 2]])
可以使用计算输入数组之间的元素最大值

A = np.array([[1,2,1,3], [2,5,2,1], [4,1,3,1]])
B = np.array([[2,1,5,1], [1,3,5,5], [4,2,1,2]])

C = np.maximum(A, B)

# array([[2, 2, 5, 3],
#        [2, 5, 5, 5],
#        [4, 2, 3, 2]])
你可以用-


这里是
np。其中
根据
a>b
的掩码在
a
b
之间进行选择,从而模拟
a
b
中对应元素之间的最大值选择,这看起来像是一个很快的选择!
np.where(a>b,a,b)