2 Nov 2000 22:46
"formstring()" in place?
Chris Barker <cbarker <at> jps.net>
2000-11-02 21:46:05 GMT
2000-11-02 21:46:05 GMT
I have a narge array of type "1" (single bytes). I need to convert it to Int32, in the manner that fromstring() would. Right now, I am doing: Array = fromstring(Array.tostring(),'f') This works fine, but what concerns me is that I need to do this on potentially HUGE arrays, and if I understand this right, I am going to create a copy with tostring, and then another copy with fromstring, that then gets referenced to Array, at which point the first original copy gets de-referenced, and should be deleted, and the temporary one gets deleted at some point in this process. I don't know when stuff created in the middle of a statement gets deleted, so I could potentially have three copies of the data around at the same time, and at least two. Since it is exactly the same C array, I'd like to be able to do this without making any copies at all. Is it possible? It seems like it should be a simple matter of changing the typecode and shape, but is this possible? While I'm asking questions: can I byteswap in place as well? The greater problem: To give a little background, and to see if anyone has a better idea of how to do what I am doing, I thought I'd run through the task that I really need to do. I am reading a binary file full of a lot of data. I have some control over the form of the file, but it needs to be compact, so I can't just make everything the same large type. The file is essentially a whole bunch of records, each of which is a collection of a couple of different(Continue reading)
>>> bits=array([1,256,256*256,256*256*256])
>>> sum(array([1,2,3,4])*bits)
67305985
So you need to reshape your array into (?,4) and multiply by bits.
And regarding your numpyio question, you can also read characters,
which are then put into an array by itself. It seems you have a very
messy file format (but the data world is never easy)
RSS Feed