[Numpy-discussion] another view puzzle

Stéfan van der Walt stefan at sun.ac.za
Wed Jun 3 18:55:12 EDT 2009

2009/6/3 Robert Kern <robert.kern at gmail.com>:
> On Wed, Jun 3, 2009 at 16:31,  <josef.pktd at gmail.com> 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:

x.view(dtype=float, type=matrix)

Not ideal, but maybe a little bit better.


More information about the NumPy-Discussion mailing list