开发者

Slicing a 2D numpy array into a 1D array

开发者 https://www.devze.com 2023-02-02 10:12 出处:网络
I have a 2D numpy array, FilteredOutput, that has 2 columns and 10001 rows, though the number of rows is a variable.

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 fo开发者_如何学JAVAund):

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. I thought it had been declared as a numpy array outside the function, but the problem was solved when I added

FilteredOutput = np.array(FilteredOutput)

before

timeSeriesArray = np.array(FilteredOutput[:,0])

note: numpy is imported as np

0

精彩评论

暂无评论...
验证码 换一张
取 消