[SciPy-user] dtype

Robert Kern robert.kern at gmail.com
Mon Jun 12 11:31:09 CDT 2006


Maik Trömel wrote:
> Hello list,
> 
> i've got a question concerning datatypes.
> I'm importing a file filled with Data with the lenght of 2 bytes via
> 
> arrh = numpy.fromstring(radFile, dtype = 'S2', count = 900*900)
> 
> Now I want to convert the data via
> 
> value = ord(arr[n][m][0]) * 256 + ord(arr[n][m][1])
> 
> But if the value in the array is NULL i get an Error:
> 
> IndexError: string index out of range

(A) In order for us to help you debug some code, you need to distill it down to
the smallest code that actually displays the error, and then provide us the
actual code.

(B) In this case, there's a better way. See below.

> So I think I have to choose another dtype. But I don't have any idea 
> which one.
> Probably someone has an idea.

arrh = numpy.fromstring(radFile, dtype=numpy.int16, count=900*900)

You don't need to do any other conversions. You may have to pay attention to
byteswapping depending on the endianness of your platform, though.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco



More information about the SciPy-user mailing list