0

I am trying to pass a list of (4, (6,7,k)) as an argument I have list of size of 4 with ndarrays of(6,7,k) and I am using this line:

test_data = np.zeros(( 6, 7, 15))
feature_list = get_Features() #list of 0 and 1s
for i in range(0, 15):
    for j in range(0, 6):
        for k in range(0, 7):
            test_data[j][k][i] = feature_list[k+ j*6 + i*15]
    x_test_list.append(test_data)
np.array(x_test_list)

As the result I am getting this error at the terminal:

ValueError: could not broadcast input array from shape (6,7,15) into shape (6,7)

Can you help me to solve why it is omitting one dimension and how it can be fixed?

Thanks

ida
  • 1,011
  • 1
  • 9
  • 17
  • Produce a [`minimal representative sample case`](https://stackoverflow.com/help/mcve)? – Divakar Apr 08 '17 at 18:03
  • My guess is that `x_test_list` has a mix of array sizes, for example one with shape (6,7) another with shape (6,7,15). `np.array([np.ones((2,3)), np.ones((2,3,4))])` produces the same error message. – hpaulj Apr 08 '17 at 18:19
  • http://stackoverflow.com/questions/43173540/how-to-keep-numpy-from-broadcasting-when-creating-an-object-array-of-different-s shows how a list of arrays can be combined into one array (or not as in your case). Results depend on whether the component shapes match, and if they don't, on how they differ. – hpaulj Apr 08 '17 at 18:26
  • @hpaulj It is true. I have 3 elements of np(6,7,15) and one of np(6,7,6). I am feeding this to one model. Do you have suggestions how I can fix this without changing the sizes? – ida Apr 08 '17 at 18:46
  • You could concatenate them on the last dimension, creating a (6,7,51) array. But I don't know if that fits your application. – hpaulj Apr 08 '17 at 19:41

0 Answers0