[Numpy-discussion] design issues - octave 'incompatibilities'
Robert Kern
rkern at ucsd.edu
Sat Jul 23 12:07:11 EDT 2005
Soeren Sonnenburg wrote:
> Dear all,
>
> I am new to numarray and as I am trying to use it day-by-day
> I am now wondering about certain numeric/numarray design issues. Please
> forgive me / correct me as I probably misunderstood certain issues.
>
> -- Why did you choose row-major instead of column major format as
> practiced by R/octave/matlab... Doesn't that mean performance problems
> as fortran/blas is optimized if you work with the transposed version ?
Not everyone is interfacing with optimized FORTRAN code. Those who are
are usually using ATLAS as their BLAS, and ATLAS has row-major versions
of the BLAS subroutines. Row-major is C's convention and
numarray/Numeric largely follow that. There are of course some
performance issues when interfacing with FORTRAN code that expects
column-major, but there would be other performance problems if
numarray/Numeric were column-major and interfacing with row-major code.
> -- why do vectors have no 'orientation', i.e. there are only row but no
> column vectors (or why do you treat matrices/vectors differently, i.e.
> have vectors at all as a separate type)
You can certainly make column vectors.
In [1]: a = arange(5)
In [2]: a
Out[2]: NumPy array, format: long
[0 1 2 3 4]
In [3]: a.shape = (5,1)
In [4]: a
Out[4]: NumPy array, format: long
[[0]
[1]
[2]
[3]
[4]]
Often, though, a "row" vector can also be used in place of a "column"
vector. Although sometimes not:
> -- How can one obtain submatrices from full matrices:
In [6]: import numarray
In [7]: a = numarray.arange(1, 10)
In [8]: a.shape = (3,3)
In [9]: a
Out[9]:
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
In [10]: i = [0,1]
In [11]: j = [[0],[2]]
In [12]: a[i,j]
Out[12]:
array([[1, 4],
[3, 6]])
> -- why don't you allow iterating over the whole matrix via a single
> index ?
ravel()
> Are there more elegant ways to do this ? Which issues are likely to be
> fixed in the future ?
None. They're not broken, just different from what you are used to.
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the NumPy-Discussion
mailing list