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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -