1

I have a list of numpy array with different shapes. I try to convert this list into a numpy array to create a batch sample for Keras. On output I want an array with the shapes (batch_size, ?, 20) where '?' is the variable dimension. I try this:

a = np.random.random((5,20))
b = np.random.random((2,20))
c = np.random.random((7,20))
d = [a,b,c]
np.array(d).shape
> (3,)

When I send this batch to Keras I have the following issue:

ValueError: Error when checking input: expected Input_Dim to have 3 dimensions, but got array with shape (3, 1)
feedMe
  • 3,431
  • 2
  • 36
  • 61
Paulo
  • 62
  • 8
  • Which number do you want for `?`? If it is the smallest shape `2`, it should be easy. If you want any other shape of `2 < ? <= 7`, you need to specify some interpolation/filling method. – JE_Muc Feb 14 '19 at 09:46
  • `?`is of variable size, I want to avoid padding. The model is able to work with variable dimensions, but it does not accept them as input. If I send data one by one (ie, batch_size=1) it works but it's awfully long, that's why I want to be able to send values directly with different shapes. – Paulo Feb 14 '19 at 09:50

1 Answers1

1

Maybe this simple example can help:

import numpy as np

a = np.random.random((5,20))
b = np.random.random((2,20))
c = np.random.random((7,20))

d = np.array([a,b,c])
print(d.shape) # (3,)

d = d[np.newaxis]
print(d.shape) # (1, 3)
Manualmsdos
  • 1,505
  • 3
  • 11
  • 22
  • Thank you, but it's not exactly what I want. After more investigations, it's impossible to do this with Numpy. – Paulo Feb 15 '19 at 14:05