python - How to get sum of two points that are tuple? -


is there anyway sum 2 points not using "class point"

input

a= (2,5) b= (3,4) c= +b  

output

(5 , 9)  

you can use comprehension plus zip:

c = tuple(a_n + b_n a_n, b_n in zip(a, b)) 

this cumbersome if need lot (not mention inefficient). if going doing sort of computation lot, you're better off using library numpy allows arrays added first-class objects.

import numpy np = np.array([2, 5]) b = np.array([3, 4]) c = + b 

if go numpy route, converting , numpy arrays bit expensive i'd recommend store points arrays rather tuple.


Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -