I have three lists.
a = [1, 2, 3, 4, 5]
b = [6, 7, 8, 9, 10]
c = [11, 12 , 13, 14, 15]
I combine them and make one list of tuples using list comprehension
combine_list = [(a1, b1, c1) for a1 in a for b1 in b for c1 in c]
This combine list has 5*5*5 = 125 elements.
Now I want to convert this combine_list into a numpy array with shape (5, 5, 5). So, I use the following code:
import numpy as np
combine_array = np.asarray(combine_list).reshape(5, 5, 5)
This gives me an error:
ValueError: total size of new array must be unchanged
But, when I try to reshape list of single 125 numbers (no tuple elements) to a numpy array, no such error occurs.
Any help on how to reshape list of tuples to a numpy array ?
np.asarray(combine_list)produce? (shape and dtype)125 * 3 = 375