In python 2.7.1 with numpy 1.5.1:
import numpy as np
B = np.matrix([[-float('inf'), 0], [0., 1]])
print B
Bm = B[1:, :]
Bm[:, 1] = float('inf')
print B
returns
[[-inf 0.]
[ 0. 1.]]
[[-inf 0.]
[ 0. inf]]
which is quite unexpected because I thought Bm was a copy (as in this question).
Any help figuring this out will be appreciated.
-float('inf')
is more directlyfloat('-inf')
, which has the benefit of not requiring a calculation (taking the opposite of a number).0.
in the matrix creation is not needed either: the presence offloat('inf')
guarantees that the matrix will be at least of floating type.