T J wrote:
>> You should be able to create a numpy array from an array.array without
>> copying the data, so this could be pretty lightweight.
>>
> Does np.asarray handle that? Or must I do something more?
You know, I'm not sure -- it's not clear to me from that docs, but it
doesn't look like it shares data:
In [48]: a1 = array.array('f', (1,2,3,4,5,6))
In [50]: npa = np.asarray(a1)
In [51]: npa
Out[51]: array([ 1., 2., 3., 4., 5., 6.])
In [52]: a1[2] = 34
In [53]: a1
Out[53]: array('f', [1.0, 2.0, 34.0, 4.0, 5.0, 6.0])
In [54]: npa
Out[54]: array([ 1., 2., 3., 4., 5., 6.])
However, np.frombuffer should work:
In [62]: a1
Out[62]: array('f', [13.0, 2.0, 34.0, 4.0, 5.0, 6.0])
In [63]: npa = np.frombuffer(a1, dtype=np.float32)
In [64]: npa
Out[64]: array([ 13., 2., 34., 4., 5., 6.], dtype=float32)
In [65]: a1[1] = 56
In [66]: npa
Out[66]: array([ 13., 56., 34., 4., 5., 6.], dtype=float32)
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
[email protected]
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev