我不明白为什么它不会广播:
import cupy as cp
popSize = 100
features = 426
maxDepth = 2
featureLoc1 = cp.zeros(shape=(popSize,features,maxDepth),dtype='int')
featureLoc1[:,:,:] = cp.arange(0,features,1)
ValueError: operands could not be broadcast together with shapes (100, 426, 426), (100, 426, 2)
这不是二维数组的处理方式吗?
IIUC,您想在尺寸为100和2的尺寸中广播np.arange,您可以这样做-
import numpy as np
popSize = 100
features = 426
maxDepth = 2
featureLoc1 = np.zeros(shape=(popSize,features,maxDepth),dtype='int')
featureLoc1[:,:,:] = np.arange(0,features,1)[None,:,None]
此处的广播将类似于此示例-
在这种情况下,在(100,426,2)和(1,426,1)之间进行广播将导致在第一个和最后一个轴上广播(100,462,2)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句