[Numpy-discussion] another view puzzle
Wed Jun 3 17:58:13 CDT 2009
On Wed, Jun 3, 2009 at 5:55 PM, Robert Kern <email@example.com> wrote:
> On Wed, Jun 3, 2009 at 16:31, <firstname.lastname@example.org> wrote:
>> On Wed, Jun 3, 2009 at 5:18 PM, Christopher Barker
>> <Chris.Barker@noaa.gov> wrote:
>>> email@example.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.
Thanks, this makes it much clearer than the current docstring for np.view().
I didn't even know about .view(ndarray_subclass) until Pierre
mentioned it today.
Do you have an opinion about whether .view(ndarray_subclass) or
__array_wrap__ is the more appropriate return wrapper for function
such as the ones in stats?
> Robert Kern
> "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
> Numpy-discussion mailing list
More information about the Numpy-discussion