[Numpy-discussion] The idiom for supporting matrices and arrays in a function
Colin J. Williams
cjw at sympatico.ca
Thu Mar 2 05:39:01 CST 2006
Travis Oliphant wrote:
> Bill Baxter wrote:
>> The NumPy for Matlab Users's wiki is currently pleading to have
>> someone fill in "/*the idiom for supporting both matrices and arrays
>> in a function". */Does anyone know what this is?
> I'm not sure what they want, exactly.
> Since a matrix is a subclass of an array you can treat them the same
> for the most part. The * and ** operators are the two that act
> differently on arrays and matrices so if you want to be sure then you
> use the functions dot and umath.multiply instead of the infix notation.
> If you want to convert arbitrary objects to "some-kind of array" then
How does asanyyarray() differ from asarray()?
> allows sub-classes of the array to pass to your function. To be
> perfectly careful, however, you will need to use explicity functions
> to perform any operation you may need.
> The other approach is to store the __array_wrap__ method of the input
> object (if there is any), convert everything to arrays using asarray()
> and then wrap the final result --- this is what ufuncs do internally.
> Again, I'm not sure what they mean?
> This SF.Net email is sponsored by xPML, a groundbreaking scripting
> that extends applications into web and mobile media. Attend the live
> and join the prime developer group breaking into this new coding
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
More information about the Numpy-discussion