[sage-devel] Re: Vector power operator not implemented

2022-06-11 Thread John H Palmieri
In my opinion it's not very mathematical. If we implement powers for 
vectors like this (and products, too, as some of these other packages do), 
then for consistency, perhaps products and powers of matrices should behave 
the same way? Ordinary matrix multiplication is much more common in 
mathematics than element-wise multiplication, and I think it would be 
awkward to have a separate operation for ordinary matrix multiplication. 
Anyway, it is easy to accomplish the same task:

sage: v = vector([1,2,3])
sage: vector([a**2 for a in v])
(1, 4, 9)

or

sage: v.apply_map(lambda x: x^2)
(1, 4, 9)

On Saturday, June 11, 2022 at 11:09:45 AM UTC-7 erent...@gmail.com wrote:

> sage -c "vector([1,2,3])^2" returns with a NotImplementedError, when in 
> other mathematics software, the same expression will operate element-wise.
>
> python:
> >>> import numpy; numpy.array([1,2,3])**2
> array([1, 4, 9])
>
> octave:
> octave:1> [1,2,3].^2
> ans = 1   4   9
>
> mathematica:
> In[1]:= {1,2,3}^2
> Out[1]= {1, 4, 9}
>
> Is there a reason this is not the way sage also implements it?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/57da3365-efad-43e0-a054-396e811e50cen%40googlegroups.com.


[sage-devel] Re: Vector power operator not implemented

2022-06-12 Thread Nils Bruin
On Saturday, 11 June 2022 at 11:09:45 UTC-7 erent...@gmail.com wrote:

> sage -c "vector([1,2,3])^2" returns with a NotImplementedError, when in 
> other mathematics software, the same expression will operate element-wise. 
>
> python: 
> >>> import numpy; numpy.array([1,2,3])**2 
> array([1, 4, 9]) 
>
> This perhaps illustrates it best:
   numpy.matrix([1,2,3])**2 
doesn't work either. A sage "vector" is a lot more like a 1-dimensional 
matrix, where multiplication is reserved for ... matrix multiplication! 
Since exponentiation is strongly tied to iterated multiplication, you end 
up only being able to take a power of a square matrix.

If you want array semantics, use arrays (there multiplication is 
element-wise, so element-wise exponentiation makes sense as well).

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/452f71e2-c58a-401c-9021-a2852ecc91d5n%40googlegroups.com.