Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.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_Numpy_Where Clause - Fatal编程技术网

Python 使用numpy,其中结果从一个数组到另一个数组

Python 使用numpy,其中结果从一个数组到另一个数组,python,numpy,where-clause,Python,Numpy,Where Clause,我有两个numpy数组-都是从同一个主数组生成的。一个是从主数组的切片生成的,另一个是从where子句生成的。我遇到的问题是,当我从where子句获取索引并将其应用于第二个数组时,我得到一个错误:只有整数标量数组可以转换为标量索引。我曾尝试使用转置转换数组,并仅使用where结果的行部分,但仍然存在相同的问题 y=np.empty([0,24]) #y array is filled with records z[:,0]=y[:,1] z[:,1]=y[:,2] z[:,3]=y[:,3]

我有两个numpy数组-都是从同一个主数组生成的。一个是从主数组的切片生成的,另一个是从where子句生成的。我遇到的问题是,当我从where子句获取索引并将其应用于第二个数组时,我得到一个错误:只有整数标量数组可以转换为标量索引。我曾尝试使用转置转换数组,并仅使用where结果的行部分,但仍然存在相同的问题

y=np.empty([0,24])
#y array is filled with records

z[:,0]=y[:,1]
z[:,1]=y[:,2]
z[:,3]=y[:,3]

#...(total of 24 columns in y and I only use 6 in the z array)
#some data calcs from y
ar = np.array(y[:,7] - y[:,8]) #PVExport
ar = [maxamount if i > maxamount else i for i in ar]
ar = [0 if i < 0 else i for i in ar]

#where clause - get all false values in column 6. the 
#here is where the error happens
naList=np.where(y[:,6]==0)


ar[naList[0]]=maxamount

z[:,4]=ar
y=np.empty([0,24])
#y数组中充满了记录
z[:,0]=y[:,1]
z[:,1]=y[:,2]
z[:,3]=y[:,3]
#…(y中总共有24列,而我在z数组中只使用了6列)
#来自y的一些数据计算
ar=np.array(y[:,7]-y[:,8])#PVExport
ar=[maxamount if i>maxamount else i for i in ar]
ar=[0如果i<0,则为0,否则i为ar中的i]
#where子句-获取第6列中的所有假值。这个
#这里是错误发生的地方
naList=np.其中(y[:,6]==0)
ar[naList[0]]=maxamount
z[:,4]=ar
当上面的行执行时-我得到错误,只有整数标量数组可以转换为标量索引

当我尝试在交互窗口中填充一个数组来做类似的事情时,它似乎起了作用


希望用y数组中某些数据计算的结果填充z数组的第4列。感谢您的帮助

ar
是一个列表,而不是一个数组。同时检查
y
。(0,24)的形状很奇怪。。
naList
看起来像什么?
ar
是一个列表,而不是一个数组。同时检查
y
。(0,24)的形状很奇怪。。
naList
看起来像什么?