0

I have a numpy list of arrays (a two-dimensional list):

db = [ch1, ch2, ch3, ch4, ch5, ch6, ch7, ch8, ch9, ch10, ch11, ch12, ch13, ch14, ch15, ch16]

I would like to perform some operations in these arrays like this:

for i in db:
 newch = (eegFilter(i)/sens)+25

How can I create a new two-dimensional list with the results of each loop iteration so that the new array would look something like this:

[[newch_iteration_1], [newch_iteration_2], [newch_iteration_3], ....]
asked Feb 25, 2014 at 5:51
2
  • 1
    Lists and arrays are very different things. A list of arrays is not a two-dimensional list, and neither a list of arrays nor a 2D list is what you should be using, which is a 2D array. If you're using NumPy, you want to avoid using lists to hold or work with numbers. What are you actually using to store your data? Commented Feb 25, 2014 at 6:03
  • thank you for the clarification. the python script reads the data from a csv file and then stores it in a 2D list to manipulate it. is this not the most efficient way. the data files are usually very big (hundreds of megs) Commented Feb 26, 2014 at 12:03

1 Answer 1

1

Use a list comprehension:

[((eegFilter(i)/sens)+25).reshape(1, *i.shape) for i in db]

Demo:

In [12]: db = [np.arange(10).reshape(2, 5), np.arange(12).reshape(3, 4)]
In [13]: [(x%2).reshape(1, *x.shape) for x in db] 
Out[13]: 
[array([[[0, 1, 0, 1, 0], 
 [1, 0, 1, 0, 1]]]), 
 array([[[0, 1, 0, 1], 
 [0, 1, 0, 1], 
 [0, 1, 0, 1]]])] 
answered Feb 25, 2014 at 5:55

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.