numpy.frombuffer != unpack() ??

Marlin Rowley marlin_rowley at hotmail.com
Fri May 16 19:24:46 EDT 2008


All: Say I have an array: a = (['rrrrggggbbbbaaaa'],['rrrrggggbbbbaaaa']) How do I make it so that I now have: starting with first element (a[0])new_arr[0] = 'r'new_arr[1] = 'g'new_arr[2] = 'b'new_arr[3] = 'a'new_arr[4] = 'r'..... continuing "through" a[1] with the same new_arrnew_arr[N] = 'r'new_arr[N+1] = 'g'.... -M


From: marlin_rowley at hotmail.comTo: robert.kern at gmail.com; python-list at python.orgSubject: RE: numpy.frombuffer != unpack() ??Date: Fri, 16 May 2008 17:31:30 -0500


Thank you!  That solved it! -M

> To: python-list at python.org> From: robert.kern at gmail.com> Subject: Re: numpy.frombuffer != unpack() ??> Date: Fri, 16 May 2008 17:25:00 -0500> > Marlin Rowley wrote:> > All:> > > > I'm getting different floating point values when I use numpy vs. unpack().> > > > frgba = numpy.frombuffer(<string of bytes>, dtype=float32)> > buffer = unpack("!f", byte)> > > > frgba[0] != buffer[0]> > > > why? This is forcing me use the unpack() function since it's giving me > > the correct values. What am I doing wrong?> > Endianness, perhaps? '!' specifies big-endian data (an alias for '>'). Most > likely, you are on a little-endian platform. All of the dtypes in numpy default > to the native-endianness unless specified. If you want to read big-endian data > using numpy, do this:> > frgba = numpy.frombuffer(<string of bytes>, dtype='>f')> > If you have any more problems with numpy, please join us on the numpy mailing > list. When reporting problems, please try to provide a small but complete > snippet of self-contained code, the output that you got, and explain the output > that you expected to get. Thank you.> > http://www.scipy.org/Mailing_Lists> > -- > 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> > --> http://mail.python.org/mailman/listinfo/python-list

E-mail for the greater good. Join the i’m Initiative from Microsoft. 
_________________________________________________________________
E-mail for the greater good. Join the i’m Initiative from Microsoft.
http://im.live.com/Messenger/IM/Join/Default.aspx?source=EML_WL_ GreaterGood
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080516/42dfd906/attachment.html>


More information about the Python-list mailing list