[Numpy-discussion] another view puzzle
Stéfan van der Walt
Wed Jun 3 17:55:12 CDT 2009
2009/6/3 Robert Kern <email@example.com>:
> On Wed, Jun 3, 2009 at 16:31, <firstname.lastname@example.org> wrote:
>> 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.
One way to distinguish the difference in code is to use
A person can even do both:
Not ideal, but maybe a little bit better.
More information about the Numpy-discussion