I have given up Matlab and I it feels great to use scipy for my scientific computing needs. However, I find that I use scipy just like I used matlab, with ipython as my terminal. Although this works OK, some things are a little frustrating: updated modules need to be reimported after modification, running scripts requires the run command etc., but this is to be expected because scipy is not matlbab. Now I don't want the matlab way necessarily and I am happy to learn a new way to do things. I guess what I would like to do is do things the python way, which I think means writing my code as classes with the _main_ bit at the end etc., but I am not sure whether that is the best way and if so, what is the best way to learn it. Does any one feel like sharing what their workflow with scipy is? Any tips for me? Thanks, Joao
Mon, 29 Sep 2008 16:31:46 +0100, João Quinta da Fonseca wrote:
I have given up Matlab and I it feels great to use scipy for my scientific computing needs. However, I find that I use scipy just like I used matlab, with ipython as my terminal. Although this works OK, some things are a little frustrating: updated modules need to be reimported after modification, running scripts requires the run command etc., but this is to be expected because scipy is not matlbab. Now I don't want the matlab way necessarily and I am happy to learn a new way to do things. I guess what I would like to do is do things the python way, which I think means writing my code as classes with the _main_ bit at the end etc., but I am not sure whether that is the best way and if so, what is the best way to learn it. Does any one feel like sharing what their workflow with scipy is? Any tips for me?
My workflow consists of two parts: 1) Long-running scripts 2) Interactive use For 1), I typically write programs that have main() and which take parameters on the command line. No code is at the module level, everything is in functions or classes. For 2), I use Ipython with ipy_autoreload and matplotlib, which gets quite close to Matlab-like usage. I can easily import routines from the script files when needed, and the autoreload takes care of reloading them for me. The usual caveats for reloading modules apply, but most of the time they are not a problem. -- Pauli Virtanen
João Quinta da Fonseca wrote:
I have given up Matlab and I it feels great to use scipy for my scientific computing needs. However, I find that I use scipy just like I used matlab, with ipython as my terminal. Although this works OK, some things are a little frustrating: updated modules need to be reimported after modification, running scripts requires the run command etc., but this is to be expected because scipy is not matlbab. Now I don't want the matlab way necessarily and I am happy to learn a new way to do things. I guess what I would like to do is do things the python way, which I think means writing my code as classes with the _main_ bit at the end etc., but I am not sure whether that is the best way and if so, what is the best way to learn it. Does any one feel like sharing what their workflow with scipy is? Any tips for me?
Apart from the data analysis software where I use scipy as a library, I practically only write scripts, without interactive use. I feel there is more control this way. I don't see much purpose in interactive use. However, you can also write procedural scripts (without classes etc.) in Python... no need to delve into OO programming if you don't need to (although I like OO personally). m. -- Massimo Sandal , Ph.D. University of Bologna Department of Biochemistry "G.Moruzzi" snail mail: Via Irnerio 48, 40126 Bologna, Italy email: massimo.sandal@unibo.it web: http://www.biocfarm.unibo.it/samori/people/sandal.html tel: +39-051-2094388 fax: +39-051-2094387
My main two uses of ipython are for: 1) Testing code at the command line that I'm trying to write in a script. Regular expressions, for example, are not something I can code in my head. 2) Using the debugger (run -d script.py). This is a huge help for me. The debugger interaction is not as good as Matlab's - for example, if you want to set a breakpoint in a module contained in a different file than your "main", there's a lot of typing. It would eventually be nice to have a graphical debugger, where you could click on the line of code to set a breakpoint. I use "reset" in ipython to re-import modules after modifying the code. The only annoying thing about that is getting prompted (yes, I really want to blow away all of my variables!) massimo sandal wrote:
João Quinta da Fonseca wrote:
I have given up Matlab and I it feels great to use scipy for my scientific computing needs. However, I find that I use scipy just like I used matlab, with ipython as my terminal. Although this works OK, some things are a little frustrating: updated modules need to be reimported after modification, running scripts requires the run command etc., but this is to be expected because scipy is not matlbab. Now I don't want the matlab way necessarily and I am happy to learn a new way to do things. I guess what I would like to do is do things the python way, which I think means writing my code as classes with the _main_ bit at the end etc., but I am not sure whether that is the best way and if so, what is the best way to learn it. Does any one feel like sharing what their workflow with scipy is? Any tips for me?
Apart from the data analysis software where I use scipy as a library, I practically only write scripts, without interactive use.
I feel there is more control this way. I don't see much purpose in interactive use.
However, you can also write procedural scripts (without classes etc.) in Python... no need to delve into OO programming if you don't need to (although I like OO personally).
m.
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
-- ------------------------------------------------------ Michael Hearne mhearne@usgs.gov (303) 273-8620 USGS National Earthquake Information Center 1711 Illinois St. Golden CO 80401 Senior Software Engineer Synergetics, Inc. ------------------------------------------------------
On Mon, Sep 29, 2008 at 9:14 AM, Michael Hearne <mhearne@usgs.gov> wrote:
My main two uses of ipython are for: 1) Testing code at the command line that I'm trying to write in a script. Regular expressions, for example, are not something I can code in my head. 2) Using the debugger (run -d script.py). This is a huge help for me. The debugger interaction is not as good as Matlab's - for example, if you want to set a breakpoint in a module contained in a different file than your "main", there's a lot of typing. It would eventually be nice to have a graphical debugger, where you could click on the line of code to set a breakpoint.
If you are an emacs user, I urge you to check out the IPython (minor?) mode, ipython.el (in the ipython distribution) . It allows much tighter integration of editor and IPython session, more like Matlab. If you're a Mac user, I'd also urge you to check out TextMate. You can achieve similar editor/command-line integration in TextMate using AppleScript (email me offline if you're interested...I haven't gotten all of the relevant code posted anywhere yet). -Barry
I use "reset" in ipython to re-import modules after modifying the code. The only annoying thing about that is getting prompted (yes, I really want to blow away all of my variables!)
massimo sandal wrote:
João Quinta da Fonseca wrote:
I have given up Matlab and I it feels great to use scipy for my scientific computing needs. However, I find that I use scipy just like I used matlab, with ipython as my terminal. Although this works OK, some things are a little frustrating: updated modules need to be reimported after modification, running scripts requires the run command etc., but this is to be expected because scipy is not matlbab. Now I don't want the matlab way necessarily and I am happy to learn a new way to do things. I guess what I would like to do is do things the python way, which I think means writing my code as classes with the _main_ bit at the end etc., but I am not sure whether that is the best way and if so, what is the best way to learn it. Does any one feel like sharing what their workflow with scipy is? Any tips for me?
Apart from the data analysis software where I use scipy as a library, I practically only write scripts, without interactive use.
I feel there is more control this way. I don't see much purpose in interactive use.
However, you can also write procedural scripts (without classes etc.) in Python... no need to delve into OO programming if you don't need to (although I like OO personally).
m.
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
-- ------------------------------------------------------ Michael Hearne mhearne@usgs.gov (303) 273-8620 USGS National Earthquake Information Center 1711 Illinois St. Golden CO 80401 Senior Software Engineer Synergetics, Inc. ------------------------------------------------------
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
João Quinta da Fonseca wrote:
I have given up Matlab and I it feels great to use scipy for my scientific computing needs. However, I find that I use scipy just like I used matlab, with ipython as my terminal. Although this works OK, some things are a little frustrating: updated modules need to be reimported after modification, running scripts requires the run command etc., but this is to be expected because scipy is not matlbab. Now I don't want the matlab way necessarily and I am happy to learn a new way to do things. I guess what I would like to do is do things the python way, which I think means writing my code as classes with the _main_ bit at the end etc., but I am not sure whether that is the best way and if so, what is the best way to learn it. Does any one feel like sharing what their workflow with scipy is? Any tips for me?
For now I use Signal WorkBench as a MatLab replacement, it misses the interactive single line statement and MatLab's workspace. Changed modules are always automatically reloaded. http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_signal_workbench.htm... And here is concrete example of filter design, compared to how we did it in MatLab http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_filter_design.html As part of the project I'm now improving the editor / debugger, which will both solve above mentioned omissions. As soon as this works well, it's almost also implemented in Signal WorkBench. http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_debug.html cheers, Stef
Thanks,
Joao
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
Using numpy version 1.1.0.dev5077 Using scipy version 0.7.0.dev4174 on Mac OS X If I do the following: x = zeros([1,1]) x[0] = 3.4756 y = squeeze(x) What is y? When I print or do arithmetic with y, it seems like it's a scalar. However, the type() function seems to indicate that it's a numpy.ndarray, but with 0 dimensionality. Questions: How do I detect when I'm in this state? How can I convert this from a (sort of) scalar into an array with length of one? --Mike -- ------------------------------------------------------ Michael Hearne mhearne@usgs.gov (303) 273-8620 USGS National Earthquake Information Center 1711 Illinois St. Golden CO 80401 Senior Software Engineer Synergetics, Inc. ------------------------------------------------------
On Mon, Oct 13, 2008 at 12:12, Michael Hearne <mhearne@usgs.gov> wrote:
Using numpy version 1.1.0.dev5077 Using scipy version 0.7.0.dev4174
on Mac OS X
If I do the following: x = zeros([1,1]) x[0] = 3.4756 y = squeeze(x)
What is y? When I print or do arithmetic with y, it seems like it's a scalar.
Why do you say that? It looks like a 0-dim array to me. In [1]: from numpy import * In [2]: x = zeros([1,1]) In [3]: x Out[3]: array([[ 0.]]) In [4]: x[0] = 3.4756 In [5]: x Out[5]: array([[ 3.4756]]) In [6]: y = squeeze(x) In [7]: y Out[7]: array(3.4756) In [8]: y.shape Out[8]: ()
However, the type() function seems to indicate that it's a numpy.ndarray, but with 0 dimensionality.
Yup.
Questions: How do I detect when I'm in this state?
isinstance(y, numpy.ndarray) and y.shape == ()
How can I convert this from a (sort of) scalar into an array with length of one?
atleast_1d(y) -- 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
Didn't know there was such a thing as a 0-dim array. It seems to _behave_ like a scalar! Problem solved... Thanks, Mike Robert Kern wrote:
On Mon, Oct 13, 2008 at 12:12, Michael Hearne <mhearne@usgs.gov> wrote:
Using numpy version 1.1.0.dev5077 Using scipy version 0.7.0.dev4174
on Mac OS X
If I do the following: x = zeros([1,1]) x[0] = 3.4756 y = squeeze(x)
What is y? When I print or do arithmetic with y, it seems like it's a scalar.
Why do you say that? It looks like a 0-dim array to me.
In [1]: from numpy import *
In [2]: x = zeros([1,1])
In [3]: x Out[3]: array([[ 0.]])
In [4]: x[0] = 3.4756
In [5]: x Out[5]: array([[ 3.4756]])
In [6]: y = squeeze(x)
In [7]: y Out[7]: array(3.4756)
In [8]: y.shape Out[8]: ()
However, the type() function seems to indicate that it's a numpy.ndarray, but with 0 dimensionality.
Yup.
Questions: How do I detect when I'm in this state?
isinstance(y, numpy.ndarray) and y.shape == ()
How can I convert this from a (sort of) scalar into an array with length of one?
atleast_1d(y)
-- ------------------------------------------------------ Michael Hearne mhearne@usgs.gov (303) 273-8620 USGS National Earthquake Information Center 1711 Illinois St. Golden CO 80401 Senior Software Engineer Synergetics, Inc. ------------------------------------------------------
participants (7)
-
Barry Wark -
João Quinta da Fonseca -
massimo sandal -
Michael Hearne -
Pauli Virtanen -
Robert Kern -
Stef Mientki