0

I have a list e of 2d arrays, which I want to flatten to get a list of 1d arrays

When I use on one element:

e[0].flatten() 

it works. But when I want to transform every element with:

enew = [e[i].flatten() for i in e] 

the failure gets raised:

IndexError: arrays used as indices must be of integer (or boolean) type 
1
  • You are indexing the array e using elements in e as indices. So when you call e[i] you are using an array (i) as an index to a list (e). As the error message suggests, only integer and boolean arrays are acceptable as indices for lists. What you want is to call flatten() on each item individually (see the answer by @YTTY). Commented Aug 18, 2020 at 14:47

2 Answers 2

3

It should be i.flatten() not e[i].flattent() I guess

Sign up to request clarification or add additional context in comments.

Comments

0

i is an index so it should be an int not a list, so:

enew = [e[i].flatten() for i in len(e)] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.