Tuesday, 20 August 2013

Numpy array: concatenate arrays and integers

Numpy array: concatenate arrays and integers

In my Python program I concatenate several integers and an array. It would
be intuitive if this would work:
x,y,z = 1,2,np.array([3,3,3])
np.concatenate((x,y,z))
However, instead all ints have to be converted to np.arrays:
x,y,z = 1,2,np.array([3,3,3])
np.concatenate((np.array([x]),np.array([y]),z))
Especially if you have many variables this manual converting is tedious.
The problem is that x and y are 0-dimensional arrays, while z is
1-dimensional. Is there any way to do the concatenation without the
converting?

No comments:

Post a Comment