ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 10 Oct 2020 11:11:32 -0500apply map in multiple dimensionhttps://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/ I have a this list
ver1=[(0.00,0.50,0.75),(0.00,−0.50,0.75),(0.50,0.75,0.00),(0.50,−0.75,0.00)]
I want apply the function `f(x,y, z)` say `0.3*ver[0][0]+ 0.7*ver[1][0]+ 0.2*ver[2][0]` to each 3-tuple of this function. I know that map do it but the exemples are for for only one variable not for 3.
I have tried to transform ver1 in matrix but after I do not know how to proceed. Perhaps it is not possible ?Sat, 10 Oct 2020 09:42:30 -0500https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/Comment by slelievre for <p>I have a this list</p>
<pre><code>ver1=[(0.00,0.50,0.75),(0.00,−0.50,0.75),(0.50,0.75,0.00),(0.50,−0.75,0.00)]
</code></pre>
<p>I want apply the function <code>f(x,y, z)</code> say <code>0.3*ver[0][0]+ 0.7*ver[1][0]+ 0.2*ver[2][0]</code> to each 3-tuple of this function. I know that map do it but the exemples are for for only one variable not for 3.</p>
<p>I have tried to transform ver1 in matrix but after I do not know how to proceed. Perhaps it is not possible ?</p>
https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?comment=53821#post-id-53821Is `ver` the same as `ver1`?
Instead of `0.3*ver[0][0]+ 0.7*ver[1][0]+ 0.2*ver[2][0]`
do you mean `0.3*ver[0][0]+ 0.7*ver[0][1]+ 0.2*ver[0][2]`?Sat, 10 Oct 2020 11:11:32 -0500https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?comment=53821#post-id-53821Comment by slelievre for <p>I have a this list</p>
<pre><code>ver1=[(0.00,0.50,0.75),(0.00,−0.50,0.75),(0.50,0.75,0.00),(0.50,−0.75,0.00)]
</code></pre>
<p>I want apply the function <code>f(x,y, z)</code> say <code>0.3*ver[0][0]+ 0.7*ver[1][0]+ 0.2*ver[2][0]</code> to each 3-tuple of this function. I know that map do it but the exemples are for for only one variable not for 3.</p>
<p>I have tried to transform ver1 in matrix but after I do not know how to proceed. Perhaps it is not possible ?</p>
https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?comment=53819#post-id-53819Do you mean you are considering the function `f(x, y, z) = 0.3*x + 0.7*y + 0.2*z`
and you have a list `ver` of 3-tuples and you want the list of `f(x, y, z)` for each
`(x, y, z)` in the list `ver`?Sat, 10 Oct 2020 11:03:47 -0500https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?comment=53819#post-id-53819Answer by slelievre for <p>I have a this list</p>
<pre><code>ver1=[(0.00,0.50,0.75),(0.00,−0.50,0.75),(0.50,0.75,0.00),(0.50,−0.75,0.00)]
</code></pre>
<p>I want apply the function <code>f(x,y, z)</code> say <code>0.3*ver[0][0]+ 0.7*ver[1][0]+ 0.2*ver[2][0]</code> to each 3-tuple of this function. I know that map do it but the exemples are for for only one variable not for 3.</p>
<p>I have tried to transform ver1 in matrix but after I do not know how to proceed. Perhaps it is not possible ?</p>
https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?answer=53820#post-id-53820Do you mean you are considering the function `f(x, y, z) = 0.3*x + 0.7*y + 0.2*z`
and you have a list `ver` of 3-tuples and you want the list of `f(x, y, z)` for each
`(x, y, z)` in the list `ver`?
Define `f` and `ver`:
sage: f = lambda x, y, z: 0.3*x + 0.7*y + 0.2*z
sage: ver = [ (0.00, 0.50, 0.75), (0.00, −0.50, 0.75), (0.50, 0.75, 0.00), (0.50, −0.75, 0.00)]
Several ways to compute the image:
sage: w = [f(x, y, z) for x, y, z in ver]
sage: w = [f(*v) for v in ver]
Or using vectors instead of tuples, and seeing `f(x, y, z)` as a scalar product:
sage: a = vector((0.3, 0.7, 0.2))
sage: w = [a * vector(v) for v in ver]
Sat, 10 Oct 2020 11:09:49 -0500https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?answer=53820#post-id-53820Answer by tmonteil for <p>I have a this list</p>
<pre><code>ver1=[(0.00,0.50,0.75),(0.00,−0.50,0.75),(0.50,0.75,0.00),(0.50,−0.75,0.00)]
</code></pre>
<p>I want apply the function <code>f(x,y, z)</code> say <code>0.3*ver[0][0]+ 0.7*ver[1][0]+ 0.2*ver[2][0]</code> to each 3-tuple of this function. I know that map do it but the exemples are for for only one variable not for 3.</p>
<p>I have tried to transform ver1 in matrix but after I do not know how to proceed. Perhaps it is not possible ?</p>
https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?answer=53818#post-id-53818You can easily turn your list of tuples into a matrix as follows:
sage: matrix(RDF, ver1)
[ 0.0 0.5 0.75]
[ 0.0 -0.5 0.75]
[ 0.5 0.75 0.0]
[ 0.5 -0.75 0.0]
Sat, 10 Oct 2020 10:22:42 -0500https://ask.sagemath.org/question/53817/apply-map-in-multiple-dimension/?answer=53818#post-id-53818