小编lpl*_*lpl的帖子

如何访问NumPy多维数组的第i列?

假设我有:

test = numpy.array([[1, 2], [3, 4], [5, 6]])
Run Code Online (Sandbox Code Playgroud)

test[i]让我第i个阵列(例如线[1, 2]).我怎样才能访问第i列?(例如[1, 3, 5]).这也是一项昂贵的操作吗?

python arrays numpy

411
推荐指数
6
解决办法
63万
查看次数

Python中此函数的最短表示

方程

目前我有:

def func(points): #Input is a matrix with n lines and 2 columns.
    centroid = numpy.mean(points, axis=0)
    sum = 0
    for point in points:
        x = point[0] - centroid[0]
        y = point[1] - centorid[1]
        sum += x**2 + y**2
    return math.sqrt(sum)
Run Code Online (Sandbox Code Playgroud)

python math

2
推荐指数
1
解决办法
1486
查看次数

标签 统计

python ×2

arrays ×1

math ×1

numpy ×1