• Welcome to Religious Forums, a friendly forum to discuss all religions in a friendly surrounding.

    Your voice is missing! You will need to register to get access to the following site features:
    • Reply to discussions and create your own threads.
    • Our modern chat room. No add-ons or extensions required, just login and start chatting!
    • Access to private conversations with other members.

    We hope to see you as a part of our community soon!

Any python programmers?

Yerda

Veteran Member
I'm working on a project using python. Anyone here good with it?

I'm looking for ways to make functions with lots of loops run faster.
 

Onyx

Active Member
Premium Member
I don't do python, but one thing that generally helps is to remove redundancy within loops by "hoisting" calculations to higher levels if possible.
 

sun rise

The world is on fire
Premium Member
Sorry. I just resurrected my perl knowledge (with a lot of google help) but can only read python not program using that language.
 

icehorse

......unaffiliated...... anti-dogmatist
Premium Member
I'm working on a project using python. Anyone here good with it?

I'm looking for ways to make functions with lots of loops run faster.

Here are some general ideas, each is useful only in certain contexts, not universally:

- create tests to break out of loops early when possible
- if the loops are nested, consider reorganizing the nesting scheme
- make sure your loops aren't doing anything that could be done outside the loops
- use Rust or C
- use short curcuits (if available)
- if you're making new "things" in your loops, find an alternative, like reusing out of scope "things"
 

Yerda

Veteran Member
Sorry. I just resurrected my perl knowledge (with a lot of google help) but can only read python not program using that language.
No worries.

I don't do python, but one thing that generally helps is to remove redundancy within loops by "hoisting" calculations to higher levels if possible.
I think this is what I'm trying.

Here are some general ideas, each is useful only in certain contexts, not universally:

- create tests to break out of loops early when possible
- if the loops are nested, consider reorganizing the nesting scheme
- make sure your loops aren't doing anything that could be done outside the loops
- use Rust or C
- use short curcuits (if available)
- if you're making new "things" in your loops, find an alternative, like reusing out of scope "things"
Thanks for the advice. I can't use anything other than python and R at the moment. Learning any of the Cs is on the list of future things I might do.

I don't use python and not programmed since i was a babe in arms. I can however suggest you take a look a vectors and see if they'll work.

A Super-Fast Way to Loop in Python
Already on it. Cheers.
 

Brickjectivity

Veteran Member
Staff member
Premium Member
I'm working on a project using python. Anyone here good with it?

I'm looking for ways to make functions with lots of loops run faster.
I am barely a programmer, but I have self studied Python 3 and written some code. I recommend The Python Cookbook which will show you a lot about the standard library. You may find both examples of good code there and ways to pass your data to compiled C code or other code. You want loops to run in C, so any standard library function which takes your data and runs it in C code then ports it back into the Python representation is a good thing. Numpy is an exemplary method for processing data in arrays. Python hands a large chunk of data to Numpy, lets Numpy process it, then takes the processed data back from Numpy.

First look at the kind of data you are processing. Then look for a library that is already available, something which Python can pass data to in a chunk (1 pass), process that data, then return a the transformed data to Python for formatting and presentation. For example if you are doing database work, don't do it directly in Python. Instead get an API that lets Python manipulate a fast database library.
 

Brickjectivity

Veteran Member
Staff member
Premium Member
I'm working on a project using python. Anyone here good with it?
Actually, just scratch out my advice; because no I am not good with it. I have temporarily lost interest and am on one of many other trails. Its a fun language, and its a great general purpose language.
 

Shaul

Well-Known Member
Premium Member
I mostly programmed in other languages but I taught two Python classes. Perhaps if you described the project better you might get hel
 

Yerda

Veteran Member
Actually, just scratch out my advice; because no I am not good with it.
Well, I did try to turn everything into numpy arrays because I read the execute faster than native python loops so it was good advice.

I mostly programmed in other languages but I taught two Python classes. Perhaps if you described the project better you might get hel
I'll post some code and I'll describe what I'm doing later on tonight or tomorrow. Thanks.
 
Top