Reputation: 1694
I have an numpy array which I want to insert 3 means into it. The array shape was (1, 23) before i inserted mean. However, it changed to (26,) after I inserted means. Is there anyway to make the shape like (1, 26) ?
the array
array([[ 266, 356, 252, 282, 3, 644, 1254, 634, 4, 711, 58,
1006, 782, 613, 565, 2, 787, 968, 640, 4, 676, 530,
573]])
the code
mean = myarray.mean()
myarray= np.append(myarray, np.array([mean,mean,mean]))
Upvotes: 1
Views: 132
Reputation: 33
m= mean.astype(int)
myarray=np.append(myarray,[[m,m,m]], axis=1)
Now following command will give output as (1, 26)
myarray.shape
Upvotes: 1
Reputation: 2939
You can specify the axis along which you append so something like this:
myarray= np.append(myarray, [[mean,mean,mean]], axis=1)
Should work. (note the extra set of brackets so that both arrays have same number of dimensions).
Upvotes: 1