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

Dharhas Pothina Dharhas.Pothina@twdb.state.tx...
Thu Jul 2 12:52:17 CDT 2009

thank you. ma.column_stack works great.

- d

>>> Pierre GM <pgmdevlist@gmail.com> 7/2/2009 11:57 AM >>>

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

> 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...

SciPy-user mailing list

More information about the SciPy-user mailing list