How to combine a mixture of different elements (matlab style) in numpy ?
[array([ 0.]), 0.0, 0.0011627, 0.0, 2.69, 0.0, array([ 3.8269, 7.0184]), array([ 4.4e-16, 2.1e+00])]
(I tried np.concatenate , but obviously it only accepts arrays as input). Basically, I want to dynamically concatenate elements from a vector by indexing. I tried:
V = np.array([1,2,3,4,5,6]) Y = np.array([7,8,9,10,11,12]) Z = np.array([V[0:2],Y[0],V[3],Y[1:3],V[4:],Y[4:]])
It works, but has array elements inside. I just need a flat vector of numbers (Matlab style), since later on I make a matrix (called RES) a bunch of these vectors. Even simple
np.savetxt('TT',RES,fmt='%1.1e')
fails because it expects to float, not arrays inside.
Guess it should be easy. np.hstack does the job. But is there any other easy way to index the Matlab style and combine vectors and scalars?
python numpy vector matlab
nahsivar
source share