将 2D numpy 数组切片为 1D 数组
我有一个 2D numpy 数组 FilteredOutput
,它有 2 列和 10001 行,但行数是一个变量。
我正在尝试获取 FilteredOutput
的第二列,并使用它来填充一个名为 timeSeriesArray
的新一维 numpy 数组,使用 我找到的一些代码):
timeSeriesArray = np.array(FilteredOutput[:,0])
但我收到以下错误消息:
TypeError: list indices must be integers, not tuple
为什么?
I have a 2D numpy array, FilteredOutput
, that has 2 columns and 10001 rows, though the number of rows is a variable.
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):
timeSeriesArray = np.array(FilteredOutput[:,0])
But I am getting the following error message:
TypeError: list indices must be integers, not tuple
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在这个问题已经解决了。问题是我没有在函数内显式声明 FilteredOutput 为 numpy 数组。 添加注释时问题就解决了
我以为它已经在函数外部声明为numpy数组,但是当我之前
:
numpy
is import asnp
This is solved now. The problem was that I had not explicitly declared FilteredOutput to be a numpy array inside the function. I thought it had been declared as a numpy array outside the function, but the problem was solved when I added
before
note:
numpy
is imported asnp