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

edited Jun 13, 2019 171 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, 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
81 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 in Python by Niroj
• 34,050 points
77 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 in Python by Niroj
• 34,050 points
34 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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,072 views
0 votes
0 answers
+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
21,398 views
0 votes
2 answers

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

readline function help to  read line in ...READ MORE

answered Jun 21 in Python by sahil
• 500 points
228 views