[SciPy-user] Add a column to masked array.

Pierre GM pgmdevlist@gmail....
Thu Jul 2 11:57:34 CDT 2009


On Jul 2, 2009, at 11:58 AM, Dharhas Pothina wrote:

> Hi,
>
> I have a masked array 'data' where data.shape = (1805,4) and another  
> masked array 'a' where a.shape = (1805,)
>
> I would like to generate a new masked array with the 'a' as the last  
> column , i.e. the final shape should be (1805,5).

Try ma.column_stack

 >>> x=ma.masked_all((10,3))
 >>> y=np.random.rand(10)
 >>> ma.column_stack((x,y)).shape
(10,4)


> I've tried np.hstack which gave an error 'arrays must have same  
> number of dimensions'

The corresponding standard numpy functions don't know how to process  
the mask and tend to fail miserably.

> and ma.hstack just combines both masked arrays into a list.

I've never been able to remember what vstack, hstack and stack do  
respectively, so I use error/trial and the online help...



More information about the SciPy-user mailing list