ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
Re: [Numpy-discussion] empty data matrix (are they really empty ?)
by Christopher Barker other posts by this author
Dec 14 2006 9:39AM messages near this date
Re: [Numpy-discussion] empty data matrix (are they really empty ?) | Re: [Numpy-discussion] Histograms of extremely large data sets
Sven Schreiber wrote:

> > In the old file I created a matrix  on the fly. I know that Numpy  and 
> > python cannot do that so I found a workaround

numpy can create matrices on the fly, in fact, you are doing  that with 
this code! The only thing it doesn't do is have a lateral that joins 
matrices the way matlab does -- you need to use vstack and the like.

> > First I create the empty matrix

To get better performance, you could create the entire empty matrix, not 
just one row -- this is the same as MATLAB -- if you know how big your 
matrix is going to be, it's better to create it first with "zeros". In 
numpy you can use either zeros or empty - just make sure that if you use 
empty, you fill the whole thing later, or you'll get garbage.

Your code:
lev2=empty((1,h))
# you've just created and empty single row
.
.
.
   lev2=vstack((lev2,clev))
#now you are creating a whole new array, with one more row than before.

The alternative:

lev2=empty((nstep+1,h)) 3 create the whole empty array
ir=1
for j in arange(1,nstep+2):
   a2=gr[arange(ir-1,ir+nstep)]
   clev=diag(dot(a2,dot(disper,a2.transpose())))
   lev2[j,:] = clev # fill in the row you've just calculated
   ir=ir+nstep+1
print lev2

I may have got some of the indexing wrong, but I hope you get the idea.

By the way, if you sent a complete, runnable sample, we can test out 
suggestions, and you'll get better answers.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@[...].gov
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thread:
Cameron Walsh
Rick White
Brian Granger
Eric Jones
Cameron Walsh
Rick White
Eric Jones
Cameron Walsh
Cameron Walsh
Eric Jones
Giorgio Luciano
Sven Schreiber
Christopher Barker
Cameron Walsh
Eric Jones

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved