473,729 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Python for programming algorithms

Hello.

I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.

However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.

I am working on my PhD Thesis, which is about Operations Research,
heuristic algorithms, etc., and I am considering the possibility of
programming all my algorithms in Python.

The usual alternative is C, but I like Python more.

The main drawbacks I see to using Python are these:

* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.

* I don't know how likely it is to find libraries in Python related to
my research field.

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context. Is Python considered as a good programming language for
implementing Operations Research algorithms, such as heuristics and
other soft-computing algorithms?

Maybe this is not the right forum, but maybe you can give me some
hints or tips...

Thank you in advance.
Jun 27 '08 #1
53 5247
Vicent Giner wrote:
Hello.

I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.

However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.

I am working on my PhD Thesis, which is about Operations Research,
heuristic algorithms, etc., and I am considering the possibility of
programming all my algorithms in Python.

The usual alternative is C, but I like Python more.

The main drawbacks I see to using Python are these:

* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.
The usual answer is that development
time is more important than running time.

Since you are likely to be using arrays,
you might look at numpy, where the
number crunching is using compiled C code.
>
* I don't know how likely it is to find libraries in Python related to
my research field.

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context. Is Python considered as a good programming language for
implementing Operations Research algorithms, such as heuristics and
other soft-computing algorithms?
Try Google with Python and your area of
interest. You could well find
Python-based packages which meet your needs.
>
Maybe this is not the right forum, but maybe you can give me some
hints or tips...

Thank you in advance.
Good luck.

Colin W.
Jun 27 '08 #2
On May 17, 5:32*pm, Vicent Giner <vgi...@gmail.c omwrote:
Hello.

I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.

However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.

I am working on my PhD Thesis, which is about Operations Research,
heuristic algorithms, etc., and I am considering the possibility of
programming all my algorithms in Python.

The usual alternative is C, but I like Python more.

The main drawbacks I see to using Python are these:

* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.

* I don't know how likely it is to find libraries in Python related to
my research field.

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context. Is Python considered as a good programming language for
implementing Operations Research algorithms, such as heuristics and
other soft-computing algorithms?

Maybe this is not the right forum, but maybe you can give me some
hints or tips...

Thank you in advance.
You're hearing from 'impossible and useless'-- neither operations.

'Stacks' are pretty important to Python (there is a Stackless Python,
I understand), which makes persistence a little more handy. It's
still a computer and still a language. You may be asking how well its
best speakers know, and look at that, I can't tell you. Some of the
fundamentals of Python may be unexplored to date, as its from the 90s,
and stacks are elements.

I, for one, will assume you're interested in control operations, which
yes Python has, and control is important. The standard library is a
good size to me (I wouldn't go doubling). There's a ready graphics
module. There are code-primitive literals, including lists -and- a
tuple. I think you're looking for the selling points of dynamic
assignment (a.barproperty= 'unheardof'), typefreeness (a= [2,'bcd']),
dynamic execution (exec('print 2'), which promotes a possibility of
self-referentiality) , type-aware function pointers, variable-length
procedure arguments, and platform independence.

I think you just asked at the right time. Yes that's an impressive
list.

There is one catch to Python, of the importance of which of the powers
that be, I am unaware. But I do know what you are liable to find on
the newsgroup. Now, with thousands of dollars of institution time on
the money, what control? I will be tentatively assuming that you are
not covertly comparing other languages. I don't think you'll like it
if you're unwise.
Jun 27 '08 #3
On May 18, 12:32 am, Vicent Giner <vgi...@gmail.c omwrote:
* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.
First of all: whatever you do, use NumPy for all numerical work (and
possibly Scipy). Remember that Python with NumPy tend to be faster
than Matlab. Anything that applies to Matlab regarding vectorization
for speed also applies to NumPy.

If your program runs too slowly, try to use the psyco jit compiler
first. If that doesn't help, try one of the following:

- use Cython or Pyrex and compile your (modified) Python code
- inline C++ using scipy.weave
- write a function in C and call it using ctypes
- write a function in Fortran and make it callable from Python using
f2py

Usually, only small bottlenecks matter when it comes to overall
performance. It is also notoriously difficult to guess where they are.
Therefore: write everything in Python first, then profile your code to
identify bottlenecks. Only important bottlenecks need to be translated
to Pyrex, C or Fortran.

http://www.scipy.org/PerformancePython

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context.
Google NumPy, SciPy, Matplolib and Sage.

NASA uses Python to process image data from the Hubble telescope.


Thank you in advance.
Jun 27 '08 #4
On May 17, 7:32*pm, Vicent Giner <vgi...@gmail.c omwrote:
Hello.

I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.

However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.

I am working on my PhD Thesis, which is about Operations Research,
heuristic algorithms, etc., and I am considering the possibility of
programming all my algorithms in Python.

The usual alternative is C, but I like Python more.

The main drawbacks I see to using Python are these:

* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.

* I don't know how likely it is to find libraries in Python related to
my research field.

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context. Is Python considered as a good programming language for
implementing Operations Research algorithms, such as heuristics and
other soft-computing algorithms?

Maybe this is not the right forum, but maybe you can give me some
hints or tips...

Thank you in advance.
I guess that python is not a good language for that. Algorithms
implemented in plain python are many times slower than C ones
(hundreds ?). In practice, algorithms are written in C and wrapped in
python. I have near zero experience in operations research, but once I
looked for linear programming toolkits for python and IIRC, I only
could find a trivial wrapper for glpk (called pulp).

My opinion: choose compiled or byte compiled languages. Choose the
language paradigm that best suit the algorithms.
Jun 27 '08 #5
what little I know:

The numbers I heard are that Python is 10-100 times slower than C. So use
Python if you can wait 10-100 times longer. Although it won't really be
that slow using numpy and/or psyco.

Python seems to have a really extensive reportoire of modules available for
it. Although I don't know about things in the math field. If what you want
is obscure enough, then you might find it for C/C++ and not Python. You
might find out in a few seconds by googling.

The advantage to Python (other than production time), is that it would be a
lot simpler and more readable simply as a syntax for conveying algorithms.
It would be like pseudo-code... but runnable. ;)

Jun 27 '08 #6
Lie
On May 18, 5:32 am, Vicent Giner <vgi...@gmail.c omwrote:
Hello.

I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.

However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.

I am working on my PhD Thesis, which is about Operations Research,
heuristic algorithms, etc., and I am considering the possibility of
programming all my algorithms in Python.

The usual alternative is C, but I like Python more.

The main drawbacks I see to using Python are these:

* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.
It is slower than a goodly written C code. C codes might be slower
than Python if the writer of C isn't very familiar with C, on the
other hand Python's implementation of things like list, dictionary,
sets, etc are a very optimized piece of code (some says it's the most
fine tuned implementation in the world) and a sloppily written array/
dict/sets implementation in C might be slower than Python.
* I don't know how likely it is to find libraries in Python related to
my research field.

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context. Is Python considered as a good programming language for
implementing Operations Research algorithms, such as heuristics and
other soft-computing algorithms?
Why not ask your peers? AFAIK (since I'm not a researcher, just a high-
school student with a "too much time" to program, I'm not even
familiar with Operation Research), in a Operation Research context (as
I understand it from wikipedia) the important thing is the algorithm
instead of pure speed, and codes are written just to describe the
algorithm you're devising. So any programming language that isn't an
esoteric language (like Whitespace or Brainfuck) would not be
considered a "just funny".
Maybe this is not the right forum, but maybe you can give me some
hints or tips...

Thank you in advance.

On May 18, 11:37*am, Dennis Lee Bieber <wlfr...@ix.net com.comwrote:
On Sat, 17 May 2008 20:25:18 -0700 (PDT), Henrique Dante de Almeida
<hda...@gmail.c omdeclaimed the following in comp.lang.pytho n:
*My opinion: choose compiled or byte compiled languages. Choose the
language paradigm that best suit the algorithms.

* * * * Python IS byte compiled -- that's what .pyc and .pyo filescontain
(strangely though, one must specify a command line argument to get the
"optimized" .pyo, rather than the .pyc with debugging data embedded).
Just to note, currently, "optimized" python code (using -O or -OO)
does very little to make your code goes faster as it doesn't (yet) do
anything but removing docstrings. The -O(ptimized) flags is reserved
to make it possible to add optimizations that might make some features
unavailable or behave differently (such as the docstrings removal that
breaks codes that uses __doc__).
Jun 27 '08 #7
Along with numpy & scipy there is some more Python scientific soft
worse to be mentioned:

http://scipy.org/Topical_Software
http://pypi.python.org/pypi?:action=...show=all&c=385

On 18 ôÒÁ, 06:25, Henrique Dante de Almeida <hda...@gmail.c omwrote:
once I
looked for linear programming toolkits for python and IIRC, I only
could find a trivial wrapper for glpk (called pulp).
You could be interested in OpenOpt, it has connections to LP solvers
glpk, cvxopt's one and lp_solve (former & latter allows handling MILP
as well)

http://scipy.org/scipy/scikits/wiki/LP
Jun 27 '08 #8
On May 18, 5:46 am, "inhahe" <inh...@gmail.c omwrote:
The numbers I heard are that Python is 10-100 times slower than C.
Only true if you use Python as if it was a dialect of Visual Basic. If
you use the right tool, like NumPy, Python can be fast enough. Also
note that Python is not slower than any other language (including C)
if the code is i/o bound. As it turns out, most code is i/o bound,
even many scientific programs.

In scientific research, CPU time is cheap and time spent programming
is expensive. Instead of optimizing code that runs too slowly, it is
often less expensive to use fancier hardware, like parallell
computers. For Python, we e.g. have mpi4py which gives us access to
MPI. It can be a good advice to write scientific software
parallelizable from the start.

I learned Pascal my first year in college. When I started programming
Matlab, I brought with me every habits of a novice Pascal programmer.
Needless to say, my programs ran excruciatingly slow. I learned C just
to write faster "mex" extensions for Matlab. But eventually, my skills
improved and I found that my Matlab programs did not need C anymore.
It took me almost 3 years to unlearn the bad habits I had acquired
while programming Pascal. It is very easy to blame the language, when
in fact it is the programmer who is not using it properly.






Jun 27 '08 #9
On Sat, 17 May 2008 15:32:29 -0700 (PDT), Vicent Giner
<vg****@gmail.c omwrote:
>Hello.

I am new to Python. It seems a very interesting language to me. Its
simplicity is very attractive.

However, it is usually said that Python is not a compiled but
interpreted programming language —I mean, it is not like C, in that
sense.

I am working on my PhD Thesis, which is about Operations Research,
heuristic algorithms, etc., and I am considering the possibility of
programming all my algorithms in Python.
Other people have said things about how to use Python
effieiently. Something that seems relevant that I don't
see mentioned:

Are you going to be doing research _about_ the
algorithms in question or is it going to be research
_using_ these algorithms to draw conclusions
about other things?

Most of the replies seem to be assuming the latter.
If it's the former then Python seems like definitely
an excellent choice - when you have want to try
something new it will be much faster trying it
out in Python, when you write up the results
there will be no need for pseudo-code as a
guide to the real code because the Python
will be just about as easy to read as the
pseudo code would be, etc.
>The usual alternative is C, but I like Python more.

The main drawbacks I see to using Python are these:

* As far as I understand, the fact that Python is not a compiled
language makes it slower than C, when performing huge amounts of
computations within an algorithm or program.

* I don't know how likely it is to find libraries in Python related to
my research field.

* I know Python is a "serious" and mature programming language, of
course. But I do not know if it is seen as "just funny" in a research
context. Is Python considered as a good programming language for
implementing Operations Research algorithms, such as heuristics and
other soft-computing algorithms?

Maybe this is not the right forum, but maybe you can give me some
hints or tips...

Thank you in advance.
David C. Ullrich
Jun 27 '08 #10

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

Similar topics

33
3979
by: Joe Cheng | last post by:
I'm curious about something... many Artima.com members who have a Java background and learned Python have come to the conclusion that Java and Python are highly complimentary languages. They would never consider filling the place Java has in their toolbox with Python, but recognize there are many tasks where it really pays to add Python to the mix. I want to ask you hard-core c.l.p Pythonistas: Do you use Python for everything? (and...
226
12634
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d1 = {'a':1} >>> d2 = {'b':2} >>> d3 = {'c':3}
68
5874
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
20
2155
by: xeys_00 | last post by:
I posted a article earlier pertaining programming for my boss. Now I am gonna ask a question about programming for myself. I just finished my first C++ Class. Next semester is a class on encryption(and it's probably gonna be a math class too). And finally back in programming in the fall with C++ and Java 1. The C++ will cover pointers, and linked lists, sorting algorithms, etc... I run linux and OS X. I have read in the old days that C was...
13
5902
by: abhinav | last post by:
Hi guys.I have to implement a topical crawler as a part of my project.What language should i implement C or Python?Python though has fast development cycle but my concern is speed also.I want to strke a balance between development speed and crawler speed.Since Python is an interpreted language it is rather slow.The crawler which will be working on huge set of pages should be as fast as possible.One possible implementation would be...
27
2054
by: hacker1017 | last post by:
im just asking out of curiosity.
2
3682
by: Xiao Jianfeng | last post by:
Hi all, I am looking for a genetic algorithms package for Python. I have googled the web before posting and found some links. The link of pygene(http://www.freenet.org.nz/python/pygene) cannot be opened. I also tried the recipe on ASPN, but it is too simple for my application, and the ga model in SciPy, which is in testing in the "sandbox".
11
3776
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 appreciate it: 1. What exactly is a Python list? If one writes a, then is the complexity Theta(n)? If this is O(1), then why was the name "list" chosen? If this is indeed Theta(n), then what alternative should be used? (array does not seem suited for...
18
7434
by: Jens | last post by:
I'm starting a project in data mining, and I'm considering Python and Java as possible platforms. I'm conserned by performance. Most benchmarks report that Java is about 10-15 times faster than Python, and my own experiments confirms this. I could imagine this to become a problem for very large datasets. How good is the integration with MySQL in Python?
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.