[英]Slicing a 2D numpy array into a 1D array
I have a 2D numpy array, FilteredOutput
, that has 2 columns and 10001 rows, though the number of rows is a variable. 我有一个二维的numpy数组
FilteredOutput
,它具有2列和10001行,尽管行数是一个变量。
I am trying to take the 2nd column of FilteredOutput
and use it to populate a new 1D numpy array called timeSeriesArray
using some code I found ): 我正在尝试使用
FilteredOutput
的第二列,并使用它找到的一些代码用它来填充一个名为timeSeriesArray
的新一维numpy数组:
timeSeriesArray = np.array(FilteredOutput[:,0])
But I am getting the following error message: 但是我收到以下错误消息:
TypeError: list indices must be integers, not tuple
Why? 为什么?
This is solved now. 现在解决了。 The problem was that I had not explicitly declared FilteredOutput to be a numpy array inside the function.
问题是我没有在函数内部明确声明FilteredOutput是一个numpy数组。 I thought it had been declared as a numpy array outside the function, but the problem was solved when I added
我以为它已在函数外部声明为numpy数组,但是当我添加时,问题就解决了
FilteredOutput = np.array(FilteredOutput)
before 之前
timeSeriesArray = np.array(FilteredOutput[:,0])
note: numpy
is imported as np
注意:
numpy
导入为np
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.