[Numpy-discussion] Converting string to array
Andrew Nesbit
alnesbit at students.cs.mu.OZ.AU
Mon May 12 23:01:03 CDT 2003
I have a string representing a sequence of 16-bit audio samples, read
in from an AIFF file like this:
f = aifc.open("filename.aiff", "r")
data = f.readframes(f.getnframes())
I can convert this to a tuple of signed 16-bit integers using the
Python standard library "array" module:
a = array.array("h", data)
This gives samples in the range [-32768, 32767] and everything is
fine.
However, instead of using module array I want to use Numeric's array
function in an equivalent way. I've been trying to do it like this:
a = Numeric.array(data, Numeric.Int16)
Now, a.itemsize() outputs 2, which seems fine, but when I iterate over
the resulting array (using standard a[i] notation), the results
indicate that the array is being treated as a sequence of 8-bit,
rather than 16-bit, integers.
What am I doing wrong here?
Thanks in advance.
Andrew.
More information about the Numpy-discussion
mailing list