numpy Structured array adding record

后端 未结 2 531
闹比i
闹比i 2021-01-29 03:46

I have an Structured array like this:

a = np.array([(0. , 1. , 2.) , (10. , 11. , 12. )] ,
             dtype=[(\'PositionX\', \'

        
2条回答
  •  甜味超标
    2021-01-29 04:30

    You're getting an error just because the a[i] are tuples, you can't add directly tuple. You have to access them, a more pythonic way to achieve this would be:

    map(sum, zip(*a))
    

    the zip function do exactly what you're looking for, after that you have to process each entry according to what you need, in your case sum , you can also try this:

    result = []
    for elem in zip(*a):
        result.append(sum(elem))
    

提交回复
热议问题