0

I have two arrays X and Y, X has size (5000,2351) and Y has (2351,). I used reshape function for Y to get size (1,2351). Then I used append function to X and instead size (5001,2351) I get (117552351,).

Y = Y.reshape(1,-1)
X = np.append(X,Y)

Where is a problem?

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
SMI9
  • 1
  • 2

2 Answers2

0

You can use np.concatenate:

X = np.arange(0,15).reshape(5,3)
Y = np.arange(0,3)
Y = Y.reshape(1,-1)

np.concatenate([X,Y])

yields:

array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11],
       [12, 13, 14],
       [ 0,  1,  2]])
Christian Sloper
  • 7,440
  • 3
  • 15
  • 28
0

from https://docs.scipy.org/doc/numpy-1.14.2/reference/generated/numpy.append.html

If axis is None, out is a flattened array You should use axis=0, or better use vstack()

numpy.append(arr, values, axis=None)[source]
Append values to the end of an array.

Parameters: 
arr : array_like

Values are appended to a copy of this array.

values : array_like

These values are appended to a copy of arr. It must be of the correct shape (the same shape as arr, excluding axis). If axis is not specified, values can be any shape and will be flattened before use.

axis : int, optional

The axis along which values are appended. If axis is not given, both arr and values are flattened before use.

Returns:    
append : ndarray

A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled. If axis is None, out is a flattened array.
Lior Cohen
  • 5,570
  • 2
  • 14
  • 30