如何计算下面每个工人的均值?以下是我的示例NumPy ndarray。第0列是工作人员编号,第1列是纬度,第2列是经度。
我想计算每个workerid的平均纬度和经度。我想保留所有使用NumPy(ndarray),而不转换为熊猫。
import numpy
from scipy.spatial.distance import cdist, euclidean
import itertools
from itertools import groupby
class WorkerPatientScores:
'''
I read from the Patient and Worker tables in SchedulingOptimization.
'''
def __init__(self, dist_weight=1):
self.a = []
self.a = ([[25302, 32.133598100000000, -94.395845200000000],
[25302, 32.145095132560200, -94.358041585705600],
[25302, 32.160400000000000, -94.330700000000000],
[25305, 32.133598100000000, -94.395845200000000],
[25305, 32.115095132560200, -94.358041585705600],
[25305, 32.110400000000000, -94.330700000000000],
[25326, 32.123598100000000, -94.395845200000000],
[25326, 32.125095132560200, -94.358041585705600],
[25326, 32.120400000000000, -94.330700000000000],
[25341, 32.173598100000000, -94.395845200000000],
[25341, 32.175095132560200, -94.358041585705600],
[25341, 32.170400000000000, -94.330700000000000],
[25376, 32.153598100000000, -94.395845200000000],
[25376, 32.155095132560200, -94.358041585705600],
[25376, 32.150400000000000, -94.330700000000000]])
ndarray = numpy.array(self.a)
ndlist = ndarray.tolist()
geo_tuple = [(p[1], p[2]) for p in ndlist]
nd1 = numpy.array(geo_tuple)
mean_tuple = numpy.mean(nd1, 0)
print(mean_tuple)
上面的输出是:
[32.14303108 -94.36152893]
30秒到达战场
临摹微笑
相关分类