[Numpy-discussion] A matrix user in the land of arrays
Fri May 9 13:41:08 CDT 2008
On Fri, May 9, 2008 at 11:23 AM, Robert Kern <email@example.com> wrote:
> On Fri, May 9, 2008 at 12:52 PM, Keith Goodman <firstname.lastname@example.org> wrote:
>> The recently proposed changes to the matrix class was the final push I
>> needed to begin slowly porting my package from matrices to arrays. But
>> I'm already stuck in the first stage (all new modules must use
>> Here's a toy example of iterating over columns of a matrix:
>> x is a nxm matrix
>> y is a nx1 matrix
>> for j in xrange(x.shape):
>> idx = where(y > scalar)
>> x[idx,j] = scalar
>> If x and y become 2d arrays, the code still works. But what confuses
>> me is how to generalize it to work for both 2d and 1d arrays.
> Use atleast_2d(x) to get a 1xm array, then use your 2D code on it.
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
I guess there is no way to not test for the shape.
More information about the Numpy-discussion