[Numpy-discussion] another view puzzle
robert.kern at gmail.com
Wed Jun 3 17:55:42 EDT 2009
On Wed, Jun 3, 2009 at 16:31, <josef.pktd at gmail.com> wrote:
> On Wed, Jun 3, 2009 at 5:18 PM, Christopher Barker
> <Chris.Barker at noaa.gov> wrote:
>> josef.pktd at gmail.com wrote:
>>> Ok, I didn't know numpy can have structured matrices,
>> well, matrices are a subclass of nd-arrays, so they support it, but it's
>> probably not the least bit useful.
>> See my earlier post to see how to do what I think you want.
>> You may not want a matrix anyway -- a 2-d array may be a better bet. the
>> only thing matrices buy you is convenient linear algebra operations.
> I'm very happy with plain numpy arrays, but to handle different data
> types in scipy.stats, I'm still trying to figure out how views and
> structured arrays work. And I'm still confused.
.view() is used two different ways, and I think that is confusing you.
.view(some_dtype) constructs a view of the array's memory with a
different dtype. This can cause a reinterpretation of the bytes of
memory. .view(ndarray_subclass) just returns an instance of
ndarray_subclass that looks at the same array (same shape, dtype,
etc.). This does not cause a reinterpretation of the memory.
These are two completely different things, unfortunately conflated
into the same method.
"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
More information about the NumPy-Discussion