Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate two arrays Python

I have arrays of size A (1, 1, 59) and B (1, 95, 59). I want to concatenate the arrays. The size of the array should be (1, 96, 59).

np.concatenate((A, B),axis =0)

Doesn't work. The error is ValueError: all the input array dimensions except for the concatenation axis must match exactly

like image 956
Krush23 Avatar asked Mar 04 '23 14:03

Krush23


1 Answers

The axis is incorrect:

>>> import numpy as np
>>> A = np.ones((1,1,59))
>>> B = np.zeros((1,56,59))
>>> np.concatenate((A, B), axis=1)
array([[[ 1.,  1.,  1., ...,  1.,  1.,  1.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        ..., 
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.]]])
>>> _.shape
(1, 57, 59)
like image 57
ForceBru Avatar answered Mar 17 '23 21:03

ForceBru