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

5
  • Produce a minimal representative sample case? Commented Apr 8, 2017 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. Commented Apr 8, 2017 at 18:19
  • stackoverflow.com/questions/43173540/… 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. Commented Apr 8, 2017 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? Commented Apr 8, 2017 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. Commented Apr 8, 2017 at 19:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.