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

2007-03-21 Thread David Koch
Ah! So much ado about nothing. What I was looking for was in fact: B[A_idx][:,A_idx] ... it's even explained in the the NumPy for Matlab Users doc on scipy.org /Thank you ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.sci

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

2007-03-20 Thread Alexander Michael
On 3/20/07, David Koch <[EMAIL PROTECTED]> wrote: > And by the way - whenever I do a .__doc__ all newline characters > are printed as "\n" in the python console ... how do I change that? The easiest way to access the doc strings is to type help() in the python interpreter, or ? in ipython (). The

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

2007-03-20 Thread David Koch
I will consider it Sven, I thought it was a good idea to collect everything which had to do with Matlab -> Python in one thread. Anyway, Specifically, I was looking for an equivalent to Matlab's "sprand" which allows one to create sparse normally distributed matrices. The function also accepts

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

2007-03-20 Thread Sven Schreiber
David Koch schrieb: > Hi, > > naive question - how do I get an overview over everything to do with > "sparse functionality" in SciPy 0.5.2 ... I can't find any documentation > anywhere. > First of all I would recommend to start a new and properly named thread for that good luck, sven __

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

2007-03-20 Thread David Koch
Hi, naive question - how do I get an overview over everything to do with "sparse functionality" in SciPy 0.5.2 ... I can't find any documentation anywhere. /David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/ma

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

2007-03-17 Thread Stefan van der Walt
On Thu, Mar 15, 2007 at 12:26:10PM +0100, David Koch wrote: > Next thing, I have > > A_Idx = array([1, 0]) > > and B is a matrix. How would I select the four elements in B indicated by > "meshgrid(A_Idx)", that ist: B[1,1], B[1,0], B[0,1], B[0,0] > In Matlab you would simply use B(A_idx, A_idx) w

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

2007-03-15 Thread David Koch
On 3/15/07, David Koch <[EMAIL PROTECTED]> 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] - re

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

2007-03-15 Thread David Koch
On 3/14/07, Gael Varoquaux <[EMAIL PROTECTED]> wrote: I definitely second this comment. Using arrays when you are trying to append a lot of data is using the wrong data format. And the code is so much more readable with lists. Thank you, I will consider it, Next thing, I have A_Idx = arr

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

2007-03-14 Thread Gael Varoquaux
On Wed, Mar 14, 2007 at 04:11:43PM +0100, Sturla Molden wrote: > On 3/14/2007 2:46 PM, Robert Cimrman wrote: > > a = [] > > while ... > > a.append( scalar ) > > a = array( a ) > While it may help, growing Python lists is also an O(N) process. > One can reduce the amount of allocations by preal

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

2007-03-14 Thread Timothy Hochberg
On 3/14/07, Sturla Molden <[EMAIL PROTECTED]> wrote: On 3/14/2007 2:46 PM, Robert Cimrman wrote: > a = [] > while ... > a.append( scalar ) > a = array( a ) While it may help, growing Python lists is also an O(N) process. This may just be a terminology problem, but just to be clear, append

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

2007-03-14 Thread Sturla Molden
On 3/14/2007 2:46 PM, Robert Cimrman wrote: > a = [] > while ... > a.append( scalar ) > a = array( a ) While it may help, growing Python lists is also an O(N) process. One can reduce the amount of allocations by preallocating an ndarray of a certain size (e.g. 1024 scalars), filling it up, an

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

2007-03-14 Thread Timothy Hochberg
On 3/14/07, David Koch <[EMAIL PROTECTED]> wrote: On 3/14/07, Sven Schreiber <[EMAIL PROTECTED]> wrote: > > > > If you want a 1d-array in the end you could try empty(0) to start with, > and then do hstack((A, your_scalar)) or something like that. Depending on what your generating routine loo

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

2007-03-14 Thread David Koch
On 3/14/07, Sven Schreiber <[EMAIL PROTECTED]> wrote: If you want a 1d-array in the end you could try empty(0) to start with, and then do hstack((A, your_scalar)) or something like that. Yeah, that works - odd, I thought concatenate((a,b),0) == hstack((a,b)) Thanks /David ___

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

2007-03-14 Thread Sven Schreiber
David Koch schrieb: > > In Python, I tried: > > A = empty((0,0)) > while > A = concatenate((A, array([someScalarValue])), 1) > end > > which returns an error since the shape of the empty A does not match the > vector I want to concatenate with. Any way to get around this without > havi

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

2007-03-14 Thread Robert Cimrman
David Koch wrote: > Hi, > > so one thing I came across now is the following, very simple: > > Matlab: > A = [] > while >A = [A some_scalar_value] > end > > > In Python, I tried: > > A = empty((0,0)) > while >A = concatenate((A, array([someScalarValue])), 1) > end > > which r

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

2007-03-14 Thread David Koch
Hi, so one thing I came across now is the following, very simple: Matlab: A = [] while A = [A some_scalar_value] end In Python, I tried: A = empty((0,0)) while A = concatenate((A, array([someScalarValue])), 1) end which returns an error since the shape of the empty A does not

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

2007-03-05 Thread David Cournapeau
David Koch wrote: > Hello, > > I am trying to translate some Matlab code to NumPy. I started reading > the NumPy book and, yeah it's a very long read :-/ One thing I am > completely confused about are the concpets of "basic" vs. "advanced" > indexing. Are there some good examples out there where

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

2007-03-05 Thread David Koch
Thank you everybody for your replies. Completely off-topic: I just read your sig Christoper: Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R Do you work with tsunami early-warning systems? I once had to give a presentation at Uni about the type of buoy

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

2007-03-05 Thread Christopher Barker
David Koch wrote: > - Is it "pythonic" to initialize vectors to 2 dimensions so that > vec.shape == (len(vec), 1) instead of vec.shape == (len(vec),)? It depends what it means -- and this is not a question of Pythonic -- maybe Numpythonic? Numpy is an n-d array package -- NOT a matrix package (

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

2007-03-05 Thread Charles R Harris
On 3/5/07, David Koch <[EMAIL PROTECTED]> wrote: Hello, I am trying to translate some Matlab code to NumPy. I started reading the NumPy book and, yeah it's a very long read :-/ One thing I am completely confused about are the concpets of "basic" vs. "advanced" indexing. Are there some good exam

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

2007-03-05 Thread Alan G Isaac
On 3/5/2007 2:13 PM, David Koch wrote: > - Given a matrix R, is there an equvialent to the Matlab > operation R(:,j) = [] (which removes column j and > "shrinks" the matrix? >>> help(numpy.delete) Help on function delete in module numpy.lib.function_base: delete(arr, obj, axis=None) Retu

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

2007-03-05 Thread Sturla Molden
On 3/5/2007 2:13 PM, David Koch wrote: > - Am I correct in assuming that all arrays have to be initialized to > their final number of elements in NumPy (using empty/zero for instance)? You can also create an array from a Python list, data in a file, another array or a memory mapping. In these c

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

2007-03-05 Thread David Koch
Hello, I am trying to translate some Matlab code to NumPy. I started reading the NumPy book and, yeah it's a very long read :-/ One thing I am completely confused about are the concpets of "basic" vs. "advanced" indexing. Are there some good examples out there where for the same piece of code - M