Hi,

You can try masked_array module:

x = np.array([[0,1,2],[3,4,5],[6,7,8]])

I3 np.ma.masked_where(x<1, x)
O3 
masked_array(data =
 [[-- 1 2]
 [3 4 5]
 [6 7 8]],
             mask =
 [[ True False False]
 [False False False]
 [False False False]],
       fill_value = 999999)

There might be a smarter solution than this, since ma tends to get slower when you deal with big data arrays. But you retain the 2D information instead of getting a flattened np.array.


On Wed, Mar 14, 2012 at 5:35 PM, jonasr <jonas.ruebsam@web.de> wrote:

Hello,

my problem is that i want to remove some small numbers of an 2d array,
for example if i want to sort out all numbers smaller then 1 of an array i
get

x=[[0,1,2],[3,4,5][6,7,8]]

c=x>=1

In [213]: c
Out[213]:
array([[False,  True,  True],
      [ True,  True,  True],
      [ True,  True,  True]], dtype=bool)

In [214]: x[c]
Out[214]: array([1, 2, 3, 4, 5, 6, 7, 8])

the problem ist that i now have a 1d array, is there any possibility to
keep the 2d structure ?

greets jonas
--
View this message in context: http://old.nabble.com/Replace-array-values-tp33506446p33506446.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion



--
Gökhan