python - converting from numpy array of one type to another by re-interpreting raw bytes -


is there way "reinterpret_cast" numpy arrays? here's example:

>>> import numpy np >>> x=np.array([105,79,196,53,151,176,59,202,249,0,207,6], dtype=np.uint8) >>> np.fromstring(x.tostring(),'<h') array([ 20329,  13764, -20329, -13765,    249,   1743], dtype=int16) 

i can call tostring() , fromstring() convert array raw bytes , array. i'm wondering if there's way me skip intermediate step. (not it's big deal, understand.)

yes. when view array different dtype, reinterpreting underlying data (zeros , ones) according different dtype.

in [85]: x.view('<i2') out[85]: array([ 20329,  13764, -20329, -13765,    249,   1743], dtype=int16) 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -