Closed
Description
Describe the issue:
Hi all,
I discover when print a (127,5) shape np.ma.array, the output is not right. But when I print it by columns, it is right again.
For example,
# print whole matrix (return wrong results for 2nd, 3rd column)
[[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[23 -- -- -- --]
[24 -- -- -- --]
[25 -- -- -- --]
[26 -- -- -- --]
[27 -- -- -- --]
[28 -- -- -- --]
[29 -- -- -- --]
[30 -- -- -- --]
[31 -- -- -- --]
[32 -- -- -- --]
[33 -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[36 -- -- -- --]
[37 -- -- -- --]
[38 -- -- -- --]
[39 -- -- -- --]
[40 -- -- -- --]
[41 -- -- -- --]
[42 -- -- -- --]
[43 -- -- -- --]
[44 -- -- -- --]
[45 -- -- -- --]
[46 -- -- -- --]
[47 -- -- -- --]
[48 -- -- -- --]
[-- -- -- -- --]
[-- -- -- 115 --]
[-- -- -- 116 --]
[-- -- -- 117 --]
[-- -- -- 118 --]
[-- -- -- 119 --]
[-- -- -- 120 --]
[-- -- -- 121 --]
[-- -- -- 122 --]
[-- -- -- 123 --]
[-- -- -- 124 --]
[-- -- -- 125 --]
[-- -- -- 126 --]
[-- -- -- 127 --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- 131 --]
[-- -- -- 132 --]
[-- -- -- 133 --]
[-- -- -- 134 --]
[-- -- -- 135 --]
[-- -- -- 136 --]
[-- -- -- 137 --]
[-- -- -- 138 --]
[-- -- -- 139 --]
[-- -- -- 140 --]
[-- -- -- 141 --]
[-- -- -- 142 --]
[-- -- -- 143 --]
[-- -- -- 144 144]
[-- -- -- 145 145]
[-- -- -- -- 146]
[-- -- -- -- 147]
[-- -- -- -- 148]
[-- -- -- -- 149]
[-- -- -- -- 150]
[-- -- -- -- 151]
[-- -- -- -- 152]
[-- -- -- -- 153]
[-- -- -- -- 154]
[-- -- -- -- 155]
[-- -- -- -- 156]
[-- -- -- -- 157]
[-- -- -- -- 158]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- --]
[-- -- -- -- 162]
[-- -- -- -- 163]
[-- -- -- -- 164]]
# print 2nd column individually
[-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- 53 54 55 56 57 58 59 60 61 62 63 64 -- -- -- 68 69 70 71
72 73 74 75 76 77 78 79 80 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --]
Reproduce the code example:
import numpy as np
def cont_lum(restframe_energy, lum, obs_bin_received, z_obs, cont_E_left, cont_E_right):
redshifted_e_mat = restframe_energy[:,np.newaxis] / (1 + z_obs)
lum = lum
bool1 = np.logical_and(redshifted_e_mat<obs_bin_received[0], redshifted_e_mat>(obs_bin_received[0]-cont_E_left))
bool2 = np.logical_and(redshifted_e_mat>obs_bin_received[1], redshifted_e_mat<(obs_bin_received[1]+cont_E_right))
bool = np.logical_or(bool1, bool2)
lum_msk = np.ma.array(lum, mask = ~bool, fill_value = 0)
print(lum_msk)# wrong output
print(lum_msk[:,1])# right output
lum1d = np.ma.median(lum_msk, axis=0)
linebool = np.logical_and(redshifted_e_mat>obs_bin_received[0], redshifted_e_mat<obs_bin_received[1])
sum_bool = linebool.sum(axis=0)
if np.isin(sum_bool,[0]).sum()!=0:
raise ValueError('Enlarge obs_bin_received larger than >1 emitting bin! There are particles luminosities not selected.')
return lum1d
restframe_energy = np.arange(0.62,0.95, 0.002)
zmax = 0.5
zmin = 0
pure = [0.652,0.654]
obsbin = [0.625,0.629]
obs_bin_received = obsbin
z_obs = np.array([0.1,0.2,0.3,0.4,0.5])
lum = np.tile(np.arange(len(restframe_energy)),(len(z_obs),1)).transpose()
lum1d= cont_lum(restframe_energy, lum, obs_bin_received, z_obs, 0.02, 0.022)
Error message:
No error raised, only print results are not right.
NumPy/Python version information:
'1.21.5' & '1.22.1'
Context for the issue:
Because even though the final results are right, the printed output array is wrong makes me feel confused. Moreover it also makes me worry about whether the numpy.ma module will return right and robust results for even larger data.