Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Masked Array: How to change symbol representing masked values [duplicate]

I'd like to change the symbol representing masked values in printed masked array. What I get is:

>>> print ma.array([[1, 0,0,1],[1,0,1,0]],mask=[[0,0,0,1],[1,1,0,1]])
[[1 0 0 --]
 [-- -- 1 --]]

I would prefer:

[[1 0 0 -]
 [- - 1 -]]

I've tried to set numpy.ma.masked_print_option, but it does not work:

>>> numpy.ma.masked_print_options = '-'
>>> print ma.array([[1, 0,0,1],[1,0,1,0]],mask=[[0,0,0,1],[1,1,0,1]])
[[1 0 0 --]
 [-- -- 1 --]]
like image 511
Waldek Avatar asked Oct 20 '15 17:10

Waldek


1 Answers

You were close!

In [4]: np.ma.masked_print_option.set_display("-")

In [5]: np.ma.array([[1, 0,0,1],[1,0,1,0]],mask=[[0,0,0,1],[1,1,0,1]])
Out[5]:
masked_array(data =
 [[1 0 0 -]
 [- - 1 -]],
             mask =
 [[False False False  True]
 [ True  True False  True]],
       fill_value = 999999)
like image 94
Randy Avatar answered Sep 30 '22 17:09

Randy