Marlin Rowley wrote:
Numpy can do this for you. First, do you really mean the array to
contain lists of one string each? If so:
kludge here
array(['r', 'r', 'r', 'r', 'g', 'g', 'g', 'g', 'b', 'b', 'b', 'b', 'a',
'a', 'a', 'a', 'r', 'r', 'r', 'r', 'g', 'g', 'g', 'g', 'b', 'b',
'b', 'b', 'a', 'a', 'a', 'a'],
dtype='|S1')
array([[['r', 'r', 'r', 'r'],
['g', 'g', 'g', 'g'],
['b', 'b', 'b', 'b'],
['a', 'a', 'a', 'a']],
[['r', 'r', 'r', 'r'],
['g', 'g', 'g', 'g'],
['b', 'b', 'b', 'b'],
['a', 'a', 'a', 'a']]],
dtype='|S1')
array([[['r', 'g', 'b', 'a'],
['r', 'g', 'b', 'a']],
[['r', 'g', 'b', 'a'],
['r', 'g', 'b', 'a']],
[['r', 'g', 'b', 'a'],
['r', 'g', 'b', 'a']],
[['r', 'g', 'b', 'a'],
['r', 'g', 'b', 'a']]],
dtype='|S1')
array(['r', 'g', 'b', 'a', 'r', 'g', 'b', 'a', 'r', 'g', 'b', 'a', 'r',
'g', 'b', 'a', 'r', 'g', 'b', 'a', 'r', 'g', 'b', 'a', 'r', 'g',
'b', 'a', 'r', 'g', 'b', 'a'],
dtype='|S1')
Done. Cool no?
Gary Herron
All:
>
Say I have an array:
>
a = (['rrrrggggbbbbaa aa'],['rrrrggggbbbbaa aa'])
>
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_arr
new_arr[N] = 'r'
new_arr[N+1] = 'g'
....
>
-M
>
Say I have an array:
>
a = (['rrrrggggbbbbaa aa'],['rrrrggggbbbbaa aa'])
>
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_arr
new_arr[N] = 'r'
new_arr[N+1] = 'g'
....
>
-M
contain lists of one string each? If so:
>>import numpy
>>a = (['rrrrggggbbbbaa aa'],['rrrrggggbbbbaa aa'])
>>b = numpy.frombuffe r(''.join(sum(a ,[])),dtype='S1') # Kind of a
>>a = (['rrrrggggbbbbaa aa'],['rrrrggggbbbbaa aa'])
>>b = numpy.frombuffe r(''.join(sum(a ,[])),dtype='S1') # Kind of a
>>b
'a', 'a', 'a', 'r', 'r', 'r', 'r', 'g', 'g', 'g', 'g', 'b', 'b',
'b', 'b', 'a', 'a', 'a', 'a'],
dtype='|S1')
>>b.shape=(2,4, 4)
>>b
>>b
['g', 'g', 'g', 'g'],
['b', 'b', 'b', 'b'],
['a', 'a', 'a', 'a']],
[['r', 'r', 'r', 'r'],
['g', 'g', 'g', 'g'],
['b', 'b', 'b', 'b'],
['a', 'a', 'a', 'a']]],
dtype='|S1')
>>c = b.transpose((2, 0,1))
>>c
>>c
['r', 'g', 'b', 'a']],
[['r', 'g', 'b', 'a'],
['r', 'g', 'b', 'a']],
[['r', 'g', 'b', 'a'],
['r', 'g', 'b', 'a']],
[['r', 'g', 'b', 'a'],
['r', 'g', 'b', 'a']]],
dtype='|S1')
>>d=c.copy() # To make it contiguous
>>d.shape = (32,)
>>d
>>d.shape = (32,)
>>d
'g', 'b', 'a', 'r', 'g', 'b', 'a', 'r', 'g', 'b', 'a', 'r', 'g',
'b', 'a', 'r', 'g', 'b', 'a'],
dtype='|S1')
Done. Cool no?
Gary Herron
>
>
>
>
------------------------------------------------------------------------
From: marlin_rowley@h otmail.com
To: robert.kern@gma il.com; python-list@python.org
Subject: RE: numpy.frombuffe r != unpack() ??
Date: Fri, 16 May 2008 17:31:30 -0500
>
Thank you! That solved it!
>
-M
>
>
------------------------------------------------------------------------
>
vs. unpack().
frgba = numpy.frombuffe r(<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
>
Endianness, perhaps? '!' specifies big-endian data (an alias for
'>'). Most
in numpy default
big-endian data
numpy mailing
complete
explain the output
harmless enigma
though it had
>
>
------------------------------------------------------------------------
E-mail for the greater good. Join the i’m Initiative from
Microsoft.
<http://im.live.com/Messenger/IM/Join/Default.aspx?so urce=EML_WL_%20 GreaterGood>
>
>
>
------------------------------------------------------------------------
E-mail for the greater good. Join the i’m Initiative from Microsoft.
<http://im.live.com/Messenger/IM/Join/Default.aspx?so urce=EML_WL_%20 GreaterGood>
>
------------------------------------------------------------------------
>
--
http://mail.python.org/mailman/listinfo/python-list
>
>
>
------------------------------------------------------------------------
From: marlin_rowley@h otmail.com
To: robert.kern@gma il.com; python-list@python.org
Subject: RE: numpy.frombuffe r != unpack() ??
Date: Fri, 16 May 2008 17:31:30 -0500
>
Thank you! That solved it!
>
-M
>
>
------------------------------------------------------------------------
>
To: python-list@python.org
From: robert.kern@gma il.com
Subject: Re: numpy.frombuffe r != unpack() ??
Date: Fri, 16 May 2008 17:25:00 -0500
>
Marlin Rowley wrote:
From: robert.kern@gma il.com
Subject: Re: numpy.frombuffe r != 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
I'm getting different floating point values when I use numpy
frgba = numpy.frombuffe r(<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
the correct values. What am I doing wrong?
Endianness, perhaps? '!' specifies big-endian data (an alias for
likely, you are on a little-endian platform. All of the dtypes
to the native-endianness unless specified. If you want to read
using numpy, do this:
>
frgba = numpy.frombuffe r(<string of bytes>, dtype='>f')
>
If you have any more problems with numpy, please join us on the
>
frgba = numpy.frombuffe r(<string of bytes>, dtype='>f')
>
If you have any more problems with numpy, please join us on the
list. When reporting problems, please try to provide a small but
snippet of self-contained code, the output that you got, and
that you expected to get. Thank you.
>
>
--
Robert Kern
>
"I have come to believe that the whole world is an enigma, a
>
>
--
Robert Kern
>
"I have come to believe that the whole world is an enigma, a
that is made terrible by our own mad attempt to interpret it as
>
------------------------------------------------------------------------
E-mail for the greater good. Join the i’m Initiative from
Microsoft.
<http://im.live.com/Messenger/IM/Join/Default.aspx?so urce=EML_WL_%20 GreaterGood>
>
>
>
------------------------------------------------------------------------
E-mail for the greater good. Join the i’m Initiative from Microsoft.
<http://im.live.com/Messenger/IM/Join/Default.aspx?so urce=EML_WL_%20 GreaterGood>
>
------------------------------------------------------------------------
>
--
http://mail.python.org/mailman/listinfo/python-list