[Numpy-discussion] A matrix user in the land of arrays

Keith Goodman kwgoodman@gmail....
Fri May 9 13:49:16 CDT 2008


On Fri, May 9, 2008 at 11:43 AM, Robert Kern <robert.kern@gmail.com> wrote:
> On Fri, May 9, 2008 at 1:41 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
>> That looks good. But at the end of the function I'll have to convert
>> back to a 1d array if the input is 1d
>>
>> np.whence_you_came_from(x)
>>
>> I guess there is no way to not test for the shape.
>
> Well, in this case, since you are modifying the data in-place, just
> return the original array.
>
> x2 = atleast_2d(x)
> x2[i,j] = something
> return x

Nice! That was the beauty of atleast_2d---it returns a view. I see now
that views are not just for speed.


More information about the Numpy-discussion mailing list