asarray (and there’s no copy) works too, so my question now is rather, why does imshow cast (I suppose that’s what it does) 32bit arrays but not 16bit ones?
Thanks for your help.
Antony
···
–
just to put my previous message on the list in case someone is interested:
Save the data below to a file “dump” and then:
plt.imshow(np.loadtxt(“dump”, dtype=np.int16))
plt.show()
Compare with:
plt.imshow(abs(np.loadtxt(“dump”, dtype=np.int16)))
or
plt.imshow(np.asfarray(np.loadtxt(…)))
I’m using ipython -wthread.
Thanks in advance,
Antony
---- file begins here
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 -2.715000000000000000e+04
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 3.017200000000000000e+04 -2.077700000000000000e+04
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 2.701700000000000000e+04 -3.205700000000000000e+04 -1.202400000000000000e+04
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 2.955400000000000000e+04 2.663400000000000000e+04 -3.077400000000000000e+04 -1.526700000000000000e+04
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 2.631200000000000000e+04 2.371900000000000000e+04 2.469500000000000000e+04 1.905200000000000000e+04 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.997700000000000000e+04 2.029400000000000000e+04 1.944000000000000000e+04 2.456500000000000000e+04 2.379300000000000000e+04 -1.739300000000000000e+04
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.982900000000000000e+04 1.571900000000000000e+04 1.890300000000000000e+04 2.588300000000000000e+04 -3.208200000000000000e+04 -2.433300000000000000e+04
---- file ends here
2010/5/6 Jon Olav Vik <jonovik@…287…>
Jon Olav Vik <jonovik@…83…> writes:
Antony Lee <antony.lee@…83…> writes:
It happens that this array has dtype=int16, and imshow’s doc says that
it only accepts float arrays
Having looked at the example you sent me, I think what you want is .astype():
a = np.array([[24695, 19052, 0],
[24565, 23793, -17393],
[ 25883, -32082, -24333]], dtype=int16)
imshow(a) # all blue
imshow(a.astype(float)) # colours!
imshow(a.astype(int)) # looks the same as using “float”
imshow(a.astype(float), interpolation=“nearest”) # without blurring
Hope this helps,
Jon Olav
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users