NumPy and Octave (qestion and discussion)

Konrad Hinsen hinsen at cnrs-orleans.fr
Thu May 25 05:15:13 EDT 2000


hzhu at rocket.knowledgetrack.com (Huaiyu Zhu) writes:

> 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:

Please keep in mind that Python is a general-purpose language, not a
specialized matrix language like Matlab. Python simply can't have an
optimized syntax for every application domain. In exchange for
non-optimal syntax for your problem, you gain a lot of convenience for
problems that do not fall precisely into a narrowly defined domain,
as well as a lot of convenience for writing non-trivial programs.

> 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.

These were conscious design decisions, so I wouldn't call them
defects. NumPy was designed using concepts from more general array
languages like APL, which work on arrays of arbitrary rank, whereas
Matlab was designed for dealing with "vectors" and "matrices", i.e.
1-d and 2-d arrays.

> (3) Default multiplication is element-wise, instead of linear algebra.

Again this reflects the specialization of Matlab to matrix problems
in contrast to NumPy's orientation towards more general array-based
calculations.

> (4) mystical expansion of 1xn * nx1 into matrix (against rule (3) above).

Nothing mystical there, it's a consequence of NumPy's general
array combination rules.

> Can NumPy be modified to look similar to octave?  I bet there would be a lot

No, because all the syntax elements you want to use for arrays are
already used for something else in Python.

What can be done is implementing "matrix" and "vector" classes which
behave like Matlab's, using NumPy arrays as an internal
representation. There even was an early attempt at such a set of
classes in the first NumPy releases, but it wasn't maintained (probably
due to lack of interest!) and finally dropped.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------



More information about the Python-list mailing list