# 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.7*ver+ 0.2*ver 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 ?

edit retag close merge delete

Do 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?

Is ver the same as ver1?

Instead of 0.3*ver+ 0.7*ver+ 0.2*ver do you mean 0.3*ver+ 0.7*ver+ 0.2*ver?

Sort by » oldest newest most voted

Do 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]

more

You 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]

more