[Tutor] problem with saving data in a text file

2013-04-23 Thread Debashish Saha
I tried the following:

Am_cor=np.vectorize(Am_cor)

#plt.plot(t, signal, color='blue', label='Original signal')
fig=plt.figure()
plt.xlabel('Time(minute)')
plt.ylabel('$ Re()$')
plt.xlim([t[0], t[-1]])
plt.ylim((-.3*a1-a1,a1+.3*a1))
plt.grid()
plt.plot(t,Am_cor(t),'o-',label='with parallax', markersize=2)
plt.legend(loc="best")
plt.show()


f = open("Amp_cor_with_parallax(sd=.001)Ilamda=5.txt", "w")
f.write("# time(minute) \tAmp_cor_with_parallax(sd=.001)
\n")  # column names
np.savetxt(f, np.array([t, Am_cor(t)]).T)
f.close()


now the error which I am getting is

   166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):

C:\Users\as\desktop\24_04_13\testing23_04.py in ()
191 f = open("Amp_cor_with_parallax(sd=.001)Ilamda=5.txt", "w")
192 f.write("# time(minute) \t
 Amp_cor_with_parallax(sd=.001) \n")  # column names
--> 193 np.savetxt(f, np.array([t, Am_cor(t)]).T)
194 f.close()
195

error: First argument must be a callable function.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Retrieving data from a text file

2013-04-09 Thread Debashish Saha
In the following you can see data from a ephemeris.txt file. Now I want to
retrieve several columns(say, for example the column starting with 00:00,
27.69 and 44.1) and name the array as x,y,z. What do I have to I tried this

x, y, z = numpy.loadtxt("ephemeris.txt", unpack=True)
And  got this error

"ValueError: could not convert string to float: Date__(UT)__HR:MN"
Could you also help me in converting that HR:MN into minute only?

Date__(UT)__HR:MN R.A.__(a-apparent)__DEC\
**\
 2013-Jan-01 00:00 *   14 31 27.69 -12 29 44.1\
 2013-Jan-01 00:01 *   14 31 27.71 -12 29 44.1\
 2013-Jan-01 00:02 *   14 31 27.72 -12 29 44.2\
 2013-Jan-01 00:03 *   14 31 27.73 -12 29 44.2\
 2013-Jan-01 00:04 *   14 31 27.75 -12 29 44.3\
 2013-Jan-01 00:05 *   14 31 27.76 -12 29 44.3\
 2013-Jan-01 00:06 *   14 31 27.77 -12 29 44.4\
 2013-Jan-01 00:07 *   14 31 27.78 -12 29 44.4\
 2013-Jan-01 00:08 *   14 31 27.80 -12 29 44.4\
 2013-Jan-01 00:09 *   14 31 27.81 -12 29 44.5\p
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to stop a program in python which is running for long time , I am using windows

2012-02-29 Thread Debashish Saha

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to stop a program in python which is running for long time

2012-02-29 Thread Debashish Saha

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem in plotting circular plates at regular separation

2012-02-14 Thread Debashish Saha
from __future__ import division
import numpy
from enthought.mayavi import mlab
for r in range (1,5):
print r

pi = numpy.pi
cos = numpy.cos
sin = numpy.sin
dphi, dtheta, dz = pi/250.0, pi/250.0, 0.01
[s,theta]=numpy.mgrid[0.01:r+0.015:.01,0:2*pi+dtheta*1.5:dtheta]
x=s*cos(theta)
y=s*sin(theta)
z=r
mlab.mesh(x, y,z, colormap='Greens')

error:

AssertionErrorTraceback (most recent call last)
C:\Users\as\ in ()
 13 y=s*sin(theta)
 14 z=r
---> 15 mlab.mesh(x, y,z, colormap='Greens')

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
the_function(*args, **kwargs)
 32 def document_pipeline(pipeline):
 33 def the_function(*args, **kwargs):
---> 34 return pipeline(*args, **kwargs)
 35
 36 if hasattr(pipeline, 'doc'):

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
__call__(self, *args, **kwargs)
 77 scene.disable_render = True
 78 # Then call the real logic

---> 79 output = self.__call_internal__(*args, **kwargs)
 80 # And re-enable the rendering, if needed.

 81 if scene is not None:

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
__call_internal__(self, *args, **kwargs)
830 filters.
831 """
--> 832 self.source = self._source_function(*args, **kwargs)
833 kwargs.pop('name', None)
834 self.store_kwargs(kwargs)

C:\Python27\lib\site-packages\mayavi\tools\sources.pyc in
grid_source(x, y, z, **kwargs)
   1259 x, y, z, scalars = convert_to_arrays((x, y, z, scalars))
   1260 data_source = MGridSource()
-> 1261 data_source.reset(x=x, y=y, z=z, scalars=scalars)
   1262
   1263 name = kwargs.pop('name', 'GridSource')

C:\Python27\lib\site-packages\mayavi\tools\sources.pyc in reset(self, **traits)
689 assert len(x.shape) == 2, "Array x must be 2 dimensional."
690 assert len(y.shape) == 2, "Array y must be 2 dimensional."
--> 691 assert len(z.shape) == 2, "Array z must be 2 dimensional."
692 assert x.shape == y.shape, "Arrays x and y must have
same shape."
693 assert y.shape == z.shape, "Arrays y and z must have
same shape."

AssertionError: Array z must be 2 dimensional.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem in ploting cylinders with different colour.

2012-02-14 Thread Debashish Saha
import numpy

from enthought.mayavi import mlab

#def test_mesh():
#"""A very pretty picture of spherical harmonics translated from

#the octaviz example."""
for r in range (1,5):
print r


pi = numpy.pi

cos = numpy.cos

sin = numpy.sin

dphi, dtheta, dz = pi/250.0, pi/250.0, 0.01

#[phi,theta] = numpy.mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
[phi,z] = numpy.mgrid[0:2*pi+dphi*1.5:dphi,0:2+dz*1.5:dz]

m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;

   # r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + 5*sin(m4*theta)**m5 +
cos(m6*theta)**m7

#x = 1*sin(phi)*cos(theta)

#y = 1*sin(phi)*sin(theta)

#z = 1*cos(phi);
x=r*cos(phi)
y=r*sin(phi)
z=z
i=['Reds','greens','autumn','purples']
print i[r-1]
e=i[r-1]

mlab.mesh(x, y, z,colormap='e')
#print i[r-1]

Error:
TypeError Traceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):

C:\Users\as\jhgf.py in ()
 24 print i[r-1]
 25 e=i[r-1]
---> 26 mlab.mesh(x, y, z,'e')
 27 #print i[r-1]

 28

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
the_function(*args, **kwargs)
 32 def document_pipeline(pipeline):
 33 def the_function(*args, **kwargs):
---> 34 return pipeline(*args, **kwargs)
 35
 36 if hasattr(pipeline, 'doc'):

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
__call__(self, *args, **kwargs)
 77 scene.disable_render = True
 78 # Then call the real logic

---> 79 output = self.__call_internal__(*args, **kwargs)
 80 # And re-enable the rendering, if needed.

 81 if scene is not None:

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
__call_internal__(self, *args, **kwargs)
830 filters.
831 """
--> 832 self.source = self._source_function(*args, **kwargs)
833 kwargs.pop('name', None)
834 self.store_kwargs(kwargs)

TypeError: grid_source() takes exactly 3 arguments (4 given)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to print a string in desired colour

2012-02-12 Thread Debashish Saha
suppose i want to print 'hello world' in color blue.so what to do?


i tried
print 'hello world','blue'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to stop a running program in python without closing python interface?

2012-02-12 Thread Debashish Saha
actually a i ran a progam in python which is sufficiently large . so i
want to stop the execution of the program now . how can i do this?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2012-02-11 Thread Debashish Saha
import numpy as np
import matplotlib.pyplot as plt
E=[81.97400737666324, 322.0939978589591, 694.5766491226185]
V0=1000
a=0.1
def V(x):
if x > -a and x < a:
return 0
return V0

V=np.vectorize(V)
#psi=np.vectorize(psi)
x= np.linspace(-1.5*a,1.5*a,100)

plt.plot(x,V(x))
plt.xlim(-5*a,5*a)
plt.ylim(-.001*V0,1.01*V0)
for m in E:
x1=np.linspace(-a,+a,100)
#y=m
#plt.xlim(-5*a,5*a)
#plt.axhline(m)
#y=np.vectorize(y)
plt.plot(x1,m)
#plt.show()
print m

Error:
---
ValueErrorTraceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):

C:\Users\as\uy.py in ()
 23 #plt.axhline(m)

 24 #y=np.vectorize(y)

---> 25 plt.plot(x1,m)
 26 #plt.show()

 27 print m

C:\Python27\lib\site-packages\matplotlib\pyplot.pyc in plot(*args, **kwargs)
   2456 ax.hold(hold)
   2457 try:
-> 2458 ret = ax.plot(*args, **kwargs)
   2459 draw_if_interactive()
   2460 finally:

C:\Python27\lib\site-packages\matplotlib\axes.pyc in plot(self, *args, **kwargs)
   3846 lines = []
   3847
-> 3848 for line in self._get_lines(*args, **kwargs):
   3849 self.add_line(line)
   3850 lines.append(line)

C:\Python27\lib\site-packages\matplotlib\axes.pyc in
_grab_next_args(self, *args, **kwargs)
321 return
322 if len(remaining) <= 3:
--> 323 for seg in self._plot_args(remaining, kwargs):
324 yield seg
325 return

C:\Python27\lib\site-packages\matplotlib\axes.pyc in _plot_args(self,
tup, kwargs)
298 x = np.arange(y.shape[0], dtype=float)
299
--> 300 x, y = self._xy_from_xy(x, y)
301
302 if self.command == 'plot':

C:\Python27\lib\site-packages\matplotlib\axes.pyc in _xy_from_xy(self, x, y)
238 y = np.atleast_1d(y)
239 if x.shape[0] != y.shape[0]:
--> 240 raise ValueError("x and y must have same first dimension")
241 if x.ndim > 2 or y.ndim > 2:
242 raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension


Question:
then how to plot those specific component of E within the square well omly?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] confusion about scipy

2012-02-08 Thread Debashish Saha
ImportError   Traceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):

C:\Users\as\hemanta\noorm.py in ()
  1 import numpy as np
> 2 from scipy import brentq
  3 import matplotlib.pyplot as plt
  4 from pylab import twinx
  5 from scipy.integrate import quad

ImportError: cannot import name brentq


Question:
like 'from pylab import twinx' why could not i write 'from scipy
import brentq'.Instead i have to write 'from scipy.optimize import
brentq'.But why???
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to change the current working directory path in ipython.

2012-02-08 Thread Debashish Saha
how to change  the current working directory path in ipython.

my current directory path is
   pwd
   Out[2]: u'C:\\Users\\as'

now if i want to take the path to a subfolder of above
'C:\\Users\\as', what do i have to do?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] confusion with else command

2012-02-07 Thread Debashish Saha
for i in range(1, 8):
print(i)
if i==3:
break
else:
print('The for loop is over')


Output:
1
2
3

Question:

but after breaking the for loop why the else loop could not work?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2012-02-07 Thread Debashish Saha
for i in range(1, 8):
print(i)
if i==3:
break
else:
print('The for loop is over')


 Output:
1
2
3

Question:but after breaking the for loop why the else command could not work?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] what is the basic difference

2012-02-06 Thread Debashish Saha
what is the basic difference between the commands
import pylab as *
import matplotlib.pyplot as plt
import numpy as np
import numpy as *
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ploting of a square well

2012-02-05 Thread Debashish Saha
-- Forwarded message --
From: Debashish Saha 
Date: Sun, Feb 5, 2012 at 7:08 PM
Subject: ploting of a square well
To: tutor@python.org


from pylab import *
x=linspace(1,1000,1)
a,b = 10,20
def v(x):
   i=5;v0=2
   for n in range(1,1+i):
       if x>(n-1)*(a+b) and xa+(n-1)*(a+b) and x<(n)*(a+b) :
           return v0
#v=vectorize(v)
plot(x,v)
show()

Error:
ValueErrorTraceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):

C:\Users\as\klj.py in ()
 10return v0
 11 #v=vectorize(v)

---> 12 plot(x,v)
 13 show()

C:\Python27\lib\site-packages\matplotlib\pyplot.pyc in plot(*args, **kwargs)
   2456 ax.hold(hold)
   2457 try:
-> 2458 ret = ax.plot(*args, **kwargs)
   2459 draw_if_interactive()
   2460 finally:

C:\Python27\lib\site-packages\matplotlib\axes.pyc in plot(self, *args, **kwargs)
   3846 lines = []
   3847
-> 3848 for line in self._get_lines(*args, **kwargs):
   3849 self.add_line(line)
   3850 lines.append(line)

C:\Python27\lib\site-packages\matplotlib\axes.pyc in
_grab_next_args(self, *args, **kwargs)
321 return
322 if len(remaining) <= 3:
--> 323 for seg in self._plot_args(remaining, kwargs):
324 yield seg
325 return

C:\Python27\lib\site-packages\matplotlib\axes.pyc in _plot_args(self,
tup, kwargs)
298 x = np.arange(y.shape[0], dtype=float)
299
--> 300 x, y = self._xy_from_xy(x, y)
301
302 if self.command == 'plot':

C:\Python27\lib\site-packages\matplotlib\axes.pyc in _xy_from_xy(self, x, y)
238 y = np.atleast_1d(y)
239 if x.shape[0] != y.shape[0]:
--> 240 raise ValueError("x and y must have same first dimension")
241 if x.ndim > 2 or y.ndim > 2:
242 raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension
Question:
what is to be edited?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] ploting of a square well

2012-02-05 Thread Debashish Saha
from pylab import *
x=linspace(1,1000,1)
a,b = 10,20
def v(x):
i=5;v0=2
for n in range(1,1+i):
if x>(n-1)*(a+b) and xa+(n-1)*(a+b) and x<(n)*(a+b) :
return v0
#v=vectorize(v)
plot(x,v)
show()

Error:
x and y must have same first dimension
Question:
what is to be edited?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2012-02-04 Thread Debashish Saha
*input:*
import numpy as np
def f(y):
return (y/5)*2*(np.pi)*0.2


*results:*
f(11)
Out[109]: 2.5132741228718345

f(11.0)
Out[110]: 2.7646015351590183

*question:*
why did i get different values for the same input?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] factorial of anumber

2012-02-04 Thread Debashish Saha
*PROGRAM TO FIND FACTORIAL OF A NUMBER(I HAVE WRITTEN IT ON GEDIT)*
x=1
n=input('enter a positive integer no:')
for i in range(1,1+n):
x=x*i
print x


*ERROR:*

enter a positive integer
no:---
EOFError  Traceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):

C:\Users\as\mnb.py in ()
  1 x=1
> 2 n=input('enter a positive integer no:')
  3 for i in range(1,1+n):
  4 x=x*i
  5 print x

EOFError: EOF when reading a line

*QUESTION*:
HOW TO ASK INPUT FROM USER THEN?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] SEE THE QUESTION AT THE BOTTOM

2012-02-03 Thread Debashish Saha
INPUT:



*for n in range(2, 1000):*

*for x in range(2, n):*

*if n % x == 0:*

*print n, 'equals', x, '*', n/x*

*break*

*else:*

*# loop fell through without finding a factor*

*print n, 'is a prime number'*

OUTPUT:

2 is a prime number

3 is a prime number

4 equals 2 * 2

5 is a prime number

6 equals 2 * 3

7 is a prime number

8 equals 2 * 4

9 equals 3 * 3

:QUESTION:

BUT I COULD NOT UNDERSTAND HOW THE COMMAND ELSE CAN WORK,THOUGH IT IS IN
THE OUTSIDE OF THE FOR LOOP IN WHICH IF COMMAND LIES.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2012-02-03 Thread Debashish Saha
what is the basic difference between numpy and pylab?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor