[Numpy-discussion] How do I make a diagonal matrix?
Travis Oliphant
oliphant at ee.byu.edu
Fri Jun 23 17:01:09 EDT 2006
Alan G Isaac wrote:
>>Alan G Isaac wrote:
>>
>>
>>>Why is a.flat not the same as a.A.flat?
>>>
>>>
>
>
>On Fri, 23 Jun 2006, Travis Oliphant apparently wrote:
>
>
>>It is the same object except for the pointer to the
>>underlying array. When asarray(a.flat) get's called it
>>looks to the underlying array to get the sub-class and
>>constructs that sub-class (and matrices can never be 1-d).
>>Thus, it's a "feature"
>>
>>
>
>
>I doubt I will prove the only one to stumble over this.
>
>I can roughly understand why a.ravel() returns a matrix;
>but is there a good reason to forbid truly flattening the matrix?
>
>
Because matrices are never 1-d. This is actually pretty consistent
behavior.
>My instincts are that a flatiter object should not have this
>hidden "feature": flatiter objects should produce
>a consistent behavior in all settings, regardless of the
>underlying array. Anything else will prove too surprising.
>
>
I think you are right that this is a bug, though. Because __array__()
(which is where the behavior comes from) should return a base-class
array (not a sub-class).
-Travis
More information about the NumPy-Discussion
mailing list