Error while converting a list into a numpy array

0 votes

I have a list

len(list) = 9260  
list[0].shape = (224,224,3)  

Now when I try to convert it to a numpy array, 

x = np.array(list)  

I get the following error:

ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)  
Jun 14, 2019 in Python by Siara

edited Jun 14, 2019 2,851 views

1 answer to this question.

0 votes
The only possible reason I could think of with this error is that probably one of your list element is not 3 dimensional. Have a closer look at your list, its data structure.
answered Jun 14, 2019 by Rhea
Thanks, @Rhea, that was the exact same issue with my list. The inner array, one element wasn't a 3 dimensional.

Related Questions In Python

0 votes
1 answer

How do I turn a list into numpy array?

Use this line: numpy_array = np.array(list) And printing/displaying the ...READ MORE

answered May 24, 2019 in Python by Isha
886 views
0 votes
1 answer

How do I read CSV data into a record array in NumPy?

Hello @kartik, You can use Numpy's genfromtxt() method to do ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,840 points
3,493 views
+1 vote
1 answer

How to convert a PIL Image into a numpy array?

Hello @kartik, You just need to convert your ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,840 points
4,580 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,125 views
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
35,468 views
0 votes
1 answer

In Python, how do I read a file line-by-line into a list?

with open(fname) as f:     content = f.readlines() # you ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,300 points
1,819 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP