as I can perform operations on arrays so that does nothing on the diagonal
is calculated such that all but the diagonal
array ([[0., 1.37, 1., 1.37, 1., 1.37, 1.]
[1.37, 0. , 1.37, 1.73, 2.37, 1.73, 1.37]
[1. , 1.37, 0. , 1.37, 2. , 2.37, 2. ]
[1.37, 1.73, 1.37, 0. , 1.37, 1.73, 2.37]
[1. , 2.37, 2. , 1.37, 0. , 1.37, 2. ]
[1.37, 1.73, 2.37, 1.73, 1.37, 0. , 1.37]
[1. , 1.37, 2. , 2.37, 2. , 1.37, 0. ]])
to avoid the NaN value, but retained the value zero on the diagonal in all responses
I wonder if masked arrays might do what you want, e.g.,
The other way to do this of is, of course, to first convert the NaNs to 0s then
mask the 0s:
Finally, it’s often efficient to mask and convert the NaNs in one step:
Pretty straightforward, just keep in mind that ‘ma’ might not yet be in your namespace and also that these functions deal with ‘NaNs’ and ‘infs’, which is usually what you want.