Python Numpy : np.int32 "slower" than np.float64
I would like to understand a strange behavior of python. Let us consider a
matrix Mwith shape 6000 x 2000. This matrix is filled with signed
integers. I want to compute np.transpose(M)*M. Two options:
When I do it "naturally" (i.e. without specifying any typing), numpy
selects the type np.int32 and the operation takes around 150s.
When I force the type to be np.float64 (using dtype=...), the same
operation takes around 2s.
How can we explain this behavior ? I was naively thinking that a int
multiplication was cheaper than a float multiplication.
Thanks a lot for your help.
No comments:
Post a Comment