Masked array: how to change a character representing masked values

I would like to change the character representing masked values ​​in printed masks. I get:

>>> 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 tried to install 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 --]]
+4
source share
1 answer

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)
+2
source

Source: https://habr.com/ru/post/1612476/


All Articles