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 13 in Python by Siara

edited Jun 13 42 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 13 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 in Python by Isha
34 views
+1 vote
2 answers

View onto a numpy array?

 just index it as you normally would. ...READ MORE

answered Oct 18, 2018 in Python by roberto
52 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
724 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 275 views
+4 votes
6 answers
+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
6,036 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,160 points
123 views