[Numpy-discussion] Matlab -> NumPy translation and indexing

David Koch ogdude@googlemail....
Thu Mar 15 08:49:53 CDT 2007


On 3/15/07, David Koch <ogdude@googlemail.com> wrote:
>
> ... NumPy equiv for Matlab B(A_idx, A_Idx)


Ok, I did like this:

A_Idx = array([1, 0])
B = random.randn(3,3)

rowInd = kron(ones((1, len(A_Idx)), int), A_Idx[:, newaxis])
colInd = kron(ones((len(A_Idx), 1), int), A_Idx)

B[rowInd, colInd] - returns the equivalent of Matlabs B(A_Idx, A_Idx)

... that cannot possibly be the easiest way :-/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070315/66e42d8b/attachment.html 


More information about the Numpy-discussion mailing list