[Numpy-discussion] .data doesn't account for .transpose()?

Glen W. Mabey Glen.Mabey@swri....
Thu Mar 29 17:25:17 CDT 2007


Hello,

I imagine that perhaps this issue I'm seeing is only an issue because I
don't thoroughly understand the buffer issues associated with numpy
arrays, but here it is anyway:

In [16]:a1 = numpy.zero
numpy.zeros       numpy.zeros_like  

In [16]:a1 = numpy.zeros( (2,2) )

In [17]:a1[0,:] = 1

In [18]:a1
Out[18]:
array([[ 1.,  1.],
       [ 0.,  0.]])

In [19]:str(a1.data)
Out[19]:'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

In [20]:a2 = a1.transpose()

In [21]:str(a2.data)
Out[21]:'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'



That is, when getting the .data from an array, if it was C_CONTIGUOUS
but was .transposed(), the .data does not reflect this operation, right?

So, would that imply that a .copy() should be done first on any array
that you want to access .data on?

Thanks,
Glen


More information about the Numpy-discussion mailing list