Ask Your Question
0

apply map in multiple dimension

asked 2020-10-10 16:42:30 +0200

Cyrille gravatar image

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 ?

edit retag flag offensive close merge delete

Comments

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?

slelievre gravatar imageslelievre ( 2020-10-10 18:03:47 +0200 )edit

Is 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]?

slelievre gravatar imageslelievre ( 2020-10-10 18:11:32 +0200 )edit

2 Answers

Sort by » oldest newest most voted
0

answered 2020-10-10 18:09:49 +0200

slelievre gravatar image

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]
edit flag offensive delete link more
1

answered 2020-10-10 17:22:42 +0200

tmonteil gravatar image

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]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-10-10 16:42:30 +0200

Seen: 237 times

Last updated: Oct 10 '20