473,287 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Using arrays in Python - problems.

Dear All,
Hello! I've just started to use Python and its a lovely
language! I've previously programmed in Fortran 95 and have just began
to use numpy. I'm having a few problems with arrays in Python though and
wondered if someone could offer me some advice?
I wrote the following Fortran code to randomly generate numbers from
a log-normal distribution for use in a Monte Carlo model:

do n=1,shotcount
F(n)=G05DEF(F_mean,F_sd)
enddo

The array F(n) is dynamically allocated earlier on and is sized with
reference to shotcount, the number of iterations the model performs. The
problem is I can't get something like this to run in Python using numpy,
and for the size of the array to be sized dynamically with reference to
the variable shotcount. I acknowledge that my knowledge of Python is
still really basic (I only started learning it a few days ago) and I'm
trying to get out of the Fortran programming mindset but I'm stuck and
don't seem to be able to get any further. If anyone could help I'd be
really grateful. Thanks very much in advance.

Best wishes,
Gareth.

--

at**************@yahoo.co.uk

665.9238429876 - Number of the Pentium Beast
Oct 23 '07 #1
4 1757

attackwarningred napisa (a):
The array F(n) is dynamically allocated earlier on and is sized with
reference to shotcount, the number of iterations the model performs. The
problem is I can't get something like this to run in Python using numpy,
and for the size of the array to be sized dynamically with reference to
the variable shotcount. I acknowledge that my knowledge of Python is
still really basic (I only started learning it a few days ago) and I'm
trying to get out of the Fortran programming mindset but I'm stuck and
don't seem to be able to get any further. If anyone could help I'd be
really grateful. Thanks very much in advance.
Hello. If you want your array to be dynamically resized at every loop
iteration, that might be quite inefficient. How about initialising it
with a required size?

F = numpy.array([0]*shotcount)
for n in xrange(shotcount):
F[n] = random.lognormvariate(F_mean, F_sd)

Hope that helps,
Marek

Oct 23 '07 #2
ma*********@wp.pl wrote:
attackwarningred napisa (a):
>The array F(n) is dynamically allocated earlier on and is sized with
reference to shotcount, the number of iterations the model performs. The
problem is I can't get something like this to run in Python using numpy,
and for the size of the array to be sized dynamically with reference to
the variable shotcount. I acknowledge that my knowledge of Python is
still really basic (I only started learning it a few days ago) and I'm
trying to get out of the Fortran programming mindset but I'm stuck and
don't seem to be able to get any further. If anyone could help I'd be
really grateful. Thanks very much in advance.

Hello. If you want your array to be dynamically resized at every loop
iteration, that might be quite inefficient. How about initialising it
with a required size?

F = numpy.array([0]*shotcount)
A more idiomatic version would be this:

F = numpy.empty((shotcount,), dtype=float)

attackwarningred, you might want to ask your numpy questions on the
numpy-discussion mailing list:

http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Oct 24 '07 #3
ma*********@wp.pl wrote:
attackwarningred napisa (a):

>>The array F(n) is dynamically allocated earlier on and is sized with
reference to shotcount, the number of iterations the model performs. The
problem is I can't get something like this to run in Python using numpy,
and for the size of the array to be sized dynamically with reference to
the variable shotcount. I acknowledge that my knowledge of Python is
still really basic (I only started learning it a few days ago) and I'm
trying to get out of the Fortran programming mindset but I'm stuck and
don't seem to be able to get any further. If anyone could help I'd be
really grateful. Thanks very much in advance.


Hello. If you want your array to be dynamically resized at every loop
iteration, that might be quite inefficient. How about initialising it
with a required size?

F = numpy.array([0]*shotcount)
for n in xrange(shotcount):
F[n] = random.lognormvariate(F_mean, F_sd)

Hope that helps,
Marek
or,

F = numpy.random.lognormal(F_mean, F_sd, shotcount)

(assuming F_mean, F_sd are the parameters of the distribution, rather
than the actual mean and standard deviation).

Duncan
Oct 24 '07 #4
Thanks very much to those who sent me a reply to my array problem! Its
now working brilliantly!

Best wishes,
Gareth.

--
ec**************@virgin.net
at**************@yahoo.co.uk

665.9238429876 - Number of the Pentium Beast
Oct 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michiel | last post by:
Hello, I am not sure this is the right place to ask. I tried the ZSI mailing list, but got no response there. My goal is to write some web services with ZSI to be used by a client written in...
0
by: mb3242 | last post by:
Hello, I'm trying to use win32com to call a method in a COM object. I'm having a problem with Python choosing the wrong type when wrapping up lists into VARIANTs. The function I'm trying to call...
13
by: Jeff Melvaine | last post by:
I note that I can write expressions like "1 << 100" and the result is stored as a long integer, which means it is stored as an integer of arbitrary length. I may need to use a large number of...
11
by: Soeren Sonnenburg | last post by:
Hi all, Just having started with python, I feel that simple array operations '*' and '+' don't do multiplication/addition but instead extend/join an array: a= >>> b= >>> a+b
5
by: Alan Howard | last post by:
We're getting "ERROR (0x8007000E) Not enough storage is available to complete this operation" errors on a fairly large, busy ASP/SQL Server web site. The error is being thrown on a line calling...
4
by: CC | last post by:
Hi there, I wanna compile a 6000x1000 array with python. The array starts from 'empty', each time I get a 6000 length list, I wanna add it to the exist array as a column vector. Is there any...
27
by: hacker1017 | last post by:
im just asking out of curiosity.
11
by: efrat | last post by:
Hello, I'm planning to use Python in order to teach a DSA (data structures and algorithms) course in an academic institute. If you could help out with the following questions, I'd sure...
30
by: Ivan Reborin | last post by:
Hello everyone, I was wondering if anyone here has a moment of time to help me with 2 things that have been bugging me. 1. Multi dimensional arrays - how do you load them in python For...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.