speed of python vs matlab.

2006-12-13 Thread Chao
I've been trying to develop some numerical codes with python, however
got disappointed.

A very simple test,

a = 1.0

for i in range(1000):
 for j in range(1000):
   a = a+1

unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
3.0G, 1G RAM, it varies according to machine configuration, but should
be in the same level)

for matlab, the same operation took 0.1 seconds,

I use numpy & scipy, they solve the problem most of the times, but
there are cases you can't avoid loops by vectors. I appreciate the
elegancy of python so much, but I guess I have to gave it up in these
numerical codes.(image processing algorithms),  for application
dev/scripting, it's still my first choice.

A good news is that the same code takes ruby 9.8 seconds.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed of python vs matlab.

2006-12-13 Thread Chao
My Bad,  the time used by python is 0.46~0.49 sec,
I tried xrange, but it doesn't make things better.

import time
tic = time.time()
a = 1.0

array = range(1000)

for i in array:
for j in array:
a = a + 0.1

toc = time.time()
print toc-tic,' has elapsed'

used by matlab is 0.012sec

tic
a = 1;
for i=1:1000
for j=1:1000
a = a + 1;
end
end
toc

used by ruby is 0.94~0.96sec

a = 1
start = Time.now()

1000.times do
  1000.times do
a = a + 1
  end
end

finish = Time.now()

puts finish - start


Andrew Sackville-West wrote:
> On Wed, Dec 13, 2006 at 04:07:20PM -0800, Chao wrote:
> > I've been trying to develop some numerical codes with python, however
> > got disappointed.
> >
> > A very simple test,
> >
> > a = 1.0
> >
> > for i in range(1000):
> >  for j in range(1000):
> >a = a+1
> >
> > unfortunately, it took 4.5 seconds to finish(my machines is fine. P4
> > 3.0G, 1G RAM, it varies according to machine configuration, but should
> > be in the same level)
>
> somethings not right there.
>
> [EMAIL PROTECTED]:~$ cat pytimetest.py
> a=1.0
> for i in range (1000):
> for j in range (1000):
>  a=a+1
>
>
> [EMAIL PROTECTED]:~$ time python pytimetest.py
>
> real0m0.534s
> user0m0.528s
> sys 0m0.000s
>
>
> [EMAIL PROTECTED]:~$ cat /proc/cpuinfo  | grep name
> model name  : Intel(R) Celeron(R) CPU 2.53GHz
>
> [EMAIL PROTECTED]:~$ uname -a
> Linux debian 2.6.18-3-686 #1 SMP Mon Dec 4 16:41:14 UTC 2006 i686
> GNU/Linux
>
> A
>
> --7AUc2qLy4jB3hD7Z
> Content-Type: application/pgp-signature
> Content-Disposition: inline;
>   filename="signature.asc"
> Content-Description: Digital signature
> X-Google-AttachSize: 190

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed of python vs matlab.

2006-12-14 Thread Chao
Thank you guys for your interest,

I tried two things 1) put code into a function 2) use psyco.

1) by putting them into a function, there is a significant improvement,
around 30%
the running time will be around 0.3sec

2) by using psyco, it really does a great job, the running time is
around 0.045sec.

While trying this another question comes up,
psyco seems to be able to optimize built-in functions & user's code, if
I call a function from an external library, it seems doesn't help.
A simple thing is I placed a = numpy.sin(a) in the loop rather than a =
a+1, in this case,
psyco doesn't have any improvement(or very little). if I put a =
math.sin(a) which is from an built-in function, it can achieve a
improvement around 3~4.   Could the reason be that numpy.sin is
actually calling a C library ?

Actually Python does show comparable/better performance than other
scripting languages. but I'm just surprised that matlab does a great
job compared to python/perl, since matlab is also a interpreted
language, I'm expecting it has silimar performance with python.

I did some search, in previous discussion, people has compared
python/numpy vs matlab,
but it is actually comparison between numpy(which is implemented in c)
vs matlab.

Chao.

import psyco
#psyco.bind(functest)
psyco.full()

import numpy
import time,math

def functest(a):
array = xrange(1000)

for i in array:
for j in array:
a = a + 1

tic = time.time()

a = 1.0
functest(a)

toc = time.time()
print toc-tic,' has elapsed'


[EMAIL PROTECTED] wrote:
> Chao, you can also try Psyco, applied on functions, and when necessary
> using its metaclass too.
> 
> Bye,
> bearophile

-- 
http://mail.python.org/mailman/listinfo/python-list


where to find shared python script?

2011-05-17 Thread Yue Chao
Dear all,

I am new to python and thank you for your help!
the first question is, is there any resource online where we can find shared
python script (like reading a csv file for ready plot making, I know to use
csv module while I find it's not good enough) .

The second one is, is there a search function in the our mailing list
archive http://mail.python.org/pipermail/python-list/. ?

Best,

Chao

-- 
***
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 77 30
Portable Phone (Mobil phone) : (33) 07 60 54  23 71

-- 
http://mail.python.org/mailman/listinfo/python-list


How to use the method loadtxt() of numpy neatly?

2013-12-19 Thread chao dong
HI, everybody. When I try to use numpy to deal with my dataset in the style 
of csv, I face a little problem.

In my dataset of the csv file, some columns are string that can not convert 
to float easily. Some of them can ignore, but other columns I need to change 
the data to a enum style.

for example, one column just contain three kinds : S,Q,C. Each of them can 
declare one meaning, so I must convert them to a dict just like {1,2,3}

Now the question is, when I use numpy.loadtxt, I must do all things above 
in just one line and one fuction. So as a new user in numpy, I don't know how 
to solve it.

Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


socket on cygwin python

2007-06-24 Thread bacon . chao
I've installed cygwin with latest python 2.5.1, but it seems that the
socket lib file do NOT support IPv6(cygwin\lib\python2.5\lib-dynload
\_socket.dll), what can I do if I want to use IPv6?
Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket on cygwin python

2007-06-24 Thread bacon . chao
On Jun 25, 1:26 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
> > I've installed cygwin with latest python 2.5.1, but it seems that the
> > socket lib file do NOT support IPv6(cygwin\lib\python2.5\lib-dynload
> > \_socket.dll), what can I do if I want to use IPv6?
>
> Use the Python binaries from python.org. If that is not acceptable,
> recompile Python for Cygwin to use WinSock2.
>
> Regards,
> Martin

Thanks Martin.

But no VC/C++ tool installed on my PC, and I think recompile this file
it seems necessary. :(
So I tried to find a binary files on Python.org, but I can't find it.
Could you tell me the binary location for the file? Thank you.

BestRegards
Ming

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: socket on cygwin python

2007-06-29 Thread bacon . chao
On Jun 26, 12:49 am, Jason Tishler <[EMAIL PROTECTED]> wrote:
> On Mon, Jun 25, 2007 at 01:53:18PM +0100, Michael Hoffman wrote:
> > [EMAIL PROTECTED] wrote:
> > > I've installed cygwin with latest python 2.5.1, but it seems that the
> > > socket lib file do NOT support IPv6(cygwin\lib\python2.5\lib-dynload
> > > \_socket.dll), what can I do if I want to use IPv6?
>
> > I don't think Cygwin supports IPv6.
>
> That was my impression too and seems to be substantiated by the
> following:
>
>http://win6.jp/Cygwin/index.html
>
> Jason
>
> --
> PGP/GPG Key:http://www.tishler.net/jason/pubkey.ascor key servers
> Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6

Got it! Thank you very much, Jason, both Michael.
I've chosen to be a Linuxer not only to solve this. :)

Ming

-- 
http://mail.python.org/mailman/listinfo/python-list


way to define static method

2007-08-22 Thread Eric CHAO
I think Python uses a very strange way to define static method in a
class. Why not make it like this?

class MyClass:
def my_static_method(self):
# self should be None as it's a static method
# just ignore self

I'm a newcomer so maybe it's quite naive. But I just wonder why it is
designed like this.

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: way to define static method

2007-08-22 Thread Eric CHAO
Thanks a lot.

Because I found a solution about static method from
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52304

And that's a little bit difficult to understand.

# direct, naive approach -- doesn't work...:
class Class1:
   def static1(name):
   print "Hello",name

# ...but now, a call such as:
Class1.static1("John")
# will fail with a TypeError, as 'static1' has become
# an unbound-method object, not a plain function.

# This is easy to solve with a simple tiny wrapper:
class Callable:
   def __init__(self, anycallable):
   self.__call__ = anycallable

# toy-example usage:
class Class2:
   def static2(name):
   print "Hi there",name
   static2 = Callable(static2)

# now, a call such as:
Class2.static2("Peter")
# works just fine, and as-expected
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for Python

2007-08-24 Thread Eric CHAO
I think many python developers don't need such an IDE actually. Just
like Ruby guys, they use a powerful editor, for example, Textmate,
instead of all-in-one IDE. It's quick and direct.

On 8/21/07, Joel Andres Granados <[EMAIL PROTECTED]> wrote:
> Hello list:
>
> I have tried various times to use an IDE for python put have always been
> disapointed.
> I haven't revisited the idea in about a year and was wondering what the
> python people
> use.
> I have also found http://pida.co.uk/main as a possible solution.  Anyone
> tried it yet?
>
> suggestions.
> Regards
> Joel Andres Granados
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


when will python 2.5 take in mainstream?

2007-02-04 Thread Eric CHAO
A lot of application based on python claim that python 2.3 or 2.4 is
needed not 2.5, ie. mysqldb. I've been using python for months. I
don't care about 2.4 or 2.5. But I like the default icons of python in
2.5. So I just use that, but some scripts can't work on that.

When will all these applications support 2.5?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


connection pool in python?

2007-02-22 Thread Eric CHAO
Connection Pool is necessary in web applications with Java and JDBC.
So does python have something like that?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


convert python scripts to exe file

2007-02-24 Thread Eric CHAO
I know py2exe can make an exe file. But python runtime dll is still
there. How can I combine the dll file into the exe, just make one
file?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to use dbstore in google app engine

2010-05-30 Thread Ou Chao
Hi all:
I have a question. How GEA save a file as simulates the App Engine
datastore in local computer? where is the file?
thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


Plotting Images

2007-07-31 Thread Pei-Yu CHAO
Hi ALL:

I have only been switched from matlab to python few
months ago. I having trouble of plotting images from a
matrix size of 8x1 (unfortunately that is the size
of my data.) 

for example,
x = rand(8,1)
inshow(x)

I have tried to use matplotlib function imshow(), but
all i get is a long thin line (unable to see the color
display and the my matrix information).

i think imshow() has the same problem in matlab, but i
think there is a alternative in matlab, imagesc().

I did search on web about plt.imagesc().but when i
try to run the example code, python just tell me
cannot find module plt.

>>>from scipy import plt
ImportError: cannot import name plt

I have installed scipy, wxpython2.6and it still
seem not to work!

is there some alternitive? or what have i done wrong? 
Thank you

Pei


  

想及時通知通訊錄裡的所有親朋好友好消息,就來 Yahoo!奇摩電子信箱發簡訊!
http://tw.mobile.yahoo.com/texts/mail.php
-- 
http://mail.python.org/mailman/listinfo/python-list