[Python-ideas] Python list of list matrixes without NumPy
pythonchb at gmail.com
Sat Apr 6 14:48:36 EDT 2019
By the way, your reply isn't go to the list --bringing it back on.
On Sat, Apr 6, 2019 at 5:03 AM Juancarlo Añez <apalala at gmail.com> wrote:
> Or maybe there is one in PyPi — have you looked?
> There's a bunch of "matrix" packages in PyPi, none of them dealing with
> the simple use cases I'm talking about.
Be careful about terminology -- "matrix" is a term from mathematics (linear
algebra) that has a specific meaning -- I don't think that's what you mean.
If it is what you mean, then what you want is numpy (though it fact, numpy
is not a matrix system -- it is general purpose n-dimensional arrays
designed for numerical computation that includes some features to support
linear algebra ).
> It could be static methods in `list`?
> x = list.matrix(n, m, default=0.0)
> y = list.matrix(n, m, o, p, default=False)
> i = list.eye(n, False, True)
If all you want are constructors for common 2-d or n-d arrays that would
create lists of lists, then make a handful of utility functions, put them
on PyPi, and see if anyone finds them useful -- if so, then offer it up as
an addition the standard list object.
But for my part, I think simple constructors are of limited utility --
sure, it's an easy source of errors to do it "wrong", e.g.:
[[None] * 5] * 6 appears to create a 2 dimensional array, but really has
all the rows as references to the same object. But users will discover this
pretty quickly, and there is something to be said for folks needing to
understand how python works with regard to multiple references to the same
But what might be more useful is a 2D or ND array class that would provide
more than just constructors, but would provide nifty things like
arr = NdArray((3,4), fill=None)
[[None, None, None, None],
[None, None, None, None],
[None, None, None, None]]
and nifty things like 2-d indexing:
arr[:, 2] to get columns, for instance.
Also some controls on resizing -- you really don't want folks able to
append arbitrarily to any of this.
THAT might gain some traction.
(or not, as you get this with numpy, and so much more, anyway.
But either way, write it and show its utility first.
Christopher Barker, PhD
Python Language Consulting
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas