NumPy and Octave (qestion and discussion)
gwhite at bodnext.bio.dfo.ca
Fri May 26 00:37:30 CEST 2000
On Wed, 24 May 2000, Huaiyu Zhu wrote:
> Question 1 (call octave from python):
> How to call octave scripts from Python? Since both support C interface, is
> this the way to go? Is there anywhere where I can find specific examples?
> What about default arguments and optional arguments?
I think of octave as being a "higher level" system than Python, so it
seems more natural to think about using octave as a shell. Octave
supports some basic unix IPC (popen, waitpid) as well as dynamically
loadable modules (using C++, not C).
> Question 2 (modify NumPy):
> I do like octave / matlab syntax for numerical computations, which is
> simple, elegant, and resembles the formulas written on paper. For example:
> From what I know, NumPy has at least the following defect compared
> with octave:
> (1) Don't distinguish row and col for 1-dim vector.
> (2) Can't identify 1xn and nx1 matrices with vectors.
> Can't identify 1x1 matrices with scalars.
> (3) Default multiplication is element-wise, instead of linear algebra.
> (4) mystical expansion of 1xn * nx1 into matrix (against rule (3) above).
> (5) No \ operator (for implicit solve of linear equations).
> Can NumPy be modified to look similar to octave? I bet there would be a lot
> of people wanting similar feature. Right now the above example is so much
> more complicated in Python:
You should ask whether octave could have been written in Python rather
than in C++. NumPy is designed to be a more general and "lower level"
tool. The question is not really whether to modify NumPy, but whether
there is need for yet another matlab clone written in Python. This could
be worthwhile as a learning project or in order to take advantage of a
particular algorithm that is already implemented in Python/NumPy. Building
octave used to be a bit of a challenge since you need to have C++ and
Fortran working together, but gcc and g77 are pretty easy to find these
days. I'd guess there are many more people using Python than octave, but
more people using octave than NumPy.
> Are there better ways to do numerical computations in python?
You don't have to stick with the low-level operations as they are
defined in NumPy. If you prefer octave-style, think about writing
an interpreter in Python that supports your requirements.
George White <gnw3 at acm.org> tel: 902.426.8509
Bedford Inst. of Oceanography, Nova Scotia, Canada.
More information about the Python-list