Skip to content Skip to sidebar Skip to footer

Creating Numpy Array From List Gives Wrong Shape

I'm creating several numpy arrays from a list of numpy arrays, like so: seq_length = 1500 seq_diff = 200 # difference between start of two sequences # x and y are 2D numpy arrays

Solution 1:

The items in x_seqs vary in length. When they are all the same length, np.array can make a 3d array from them; when they differ it makes an object array of lists. Look at the dtype of x_test. Look at the [len(i) for i in x_test].

I took your code, added:

x=np.zeros((2000,10))
y=x.copy()
...
print([len(i) for i in x_seqs])
print(x_train.shape)
print(x_valid.shape)
print(x_test.shape)

and got:

1520:~/mypy$ python3 stack40643639.py 
[1500, 1500, 1500, 1400, 1200, 1000, 800, 600, 400, 200]
(7,)
(1, 600, 10)
(2,)

Post a Comment for "Creating Numpy Array From List Gives Wrong Shape"