[PYTHON MATRIX-SIG] First experiences
James Hugunin
jjh@Goldilocks.LCS.MIT.EDU
Tue, 30 Jan 96 12:54:22 EST
From: hinsenk@ERE.UMontreal.CA (Hinsen Konrad)
I don't know whether or not sum even belongs in the set of standard
functions. On the one hand I'd rather make people use add.reduce
because it's much more in the spirit of the array object. On the
other hand, sum is such a friendly little function. If it remains in
the system, then I agree it should get the second argument.
In the spirit of "no needless redundancies", it would be better not to
have this function. Maybe we should add an (optional) module with
standard abbreviations, where we would simply write sum =
add.reduce. That would also be a good way to have clearer standard
names for things like arange() while still having short alternatives
that are available on every system.
I think I like this idea, I'll play with it and see what I come up with.
What you suggest would be very easy to code, but I don't want it
included in the behavior for reshape. I like having reshape error
check my dimensions for me, and I like the fact that reshape doesn't
copy the whole array, but just returns a new pointer to it.
It could still return a new pointer if the size is the same,
and make a copy only if the size changes. Personally I don't care
This I REALLY don't want. I firmly believe that whether a function
returns a pointer or a copy should not be dependent on its arguments.
about dimension checking; in all my APL code that has never been
a problem. If the size remains the same, then typically the
new dimensions are specified as an expression involving the old
dimensions. I have never had an error there.
Try this:
a = array([1,2,3])
a.concat([4,5], [7,8])
-> array([1,2,3,4,5,7,8])
I assume that this is what you're looking for?
Not really. First of all, in most cases I need a non-destructive
version, similar to sequence addition. Second, I really need
it for all dimensions. In my application, I have two 1d arrays
of equal length and have to construct a 2d array from them.
What I used is
c = array([tuple(a), tuple(b)])
but there ought to be a much cleaner and more efficient way.
Well, you should use c = array([a, b]) for that. This seems fairly
clean to me, and will run quite efficiently if a and b are already
arrays of the same type.
What do you mean by non-destructive? a.concat(b) does not modify a,
but instead returns a new array that is b concatenated with a. This
is almost exactly equivalent to a+b if a and b were lists.
BTW, we also ought to have a way to convert arrays to nested
lists and maybe tuples. Oddly enough, Python has no built-in
function list(), although it does have tuple().
I agree, I'll add this when I get the time. I'll probablyu call it
toList() to go along with toString and toFile.
It should probably work along any axis, but I don't have a terribly
good way to specify the axis and still keep the nice feature of being
able to concat together an arbitrary number of arrays (very important
One argument could be a tuple of all arrays to be concatenated.
This doesn't work nicely if you only have one array.
for efficiency). It would also be a bit of a hassle to write in C the
way you're suggesting, would it be enough to add in a standard python
function with the desired behavior?
That's just a matter of efficiency and has to be tried. In my APL code
this function is used a lot, and often on small arrays.
Again, what would you call this new method?
-Jim
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================