尝试使用IronPython做线性代数

时间:2018-12-21 13:02:04

标签: python linear-algebra ironpython mathematical-optimization

在CPython中,我将使用numpy.linalg进行线性代数(svd)计算,但是numpy在IronPython中不起作用(我在multiarray模块中遇到导入错误)。 IronPython是强制性的,因为我使用的软件带有嵌入式IronPython。

我在互联网上找不到用于IronPython的函数库...有人知道一个很好的库,对于IronPython以及对Windows和Linux都没有什么依赖?

实际上,我的目标是从一组点中找到一个中间平面。我在互联网上找到了此代码:

def planeFit(points):
    """
    p, n = planeFit(points)

    Given an array, points, of shape (d,...)
    representing points in d-dimensional space,
    fit an d-dimensional plane to the points.

    Return a point, p, on the plane (the point-cloud centroid),
    and the normal, n.
    """
    import numpy as np
    from numpy.linalg import svd
    points = np.reshape(points, (np.shape(points)[0], -1))  # Collapse trialing dimensions
    assert points.shape[0] <= points.shape[1], "There are only %s points in %s dimensions." % (points.shape[1], points.shape[0])
    ctr = points.mean(axis=1)
    x = points - ctr[:, np.newaxis]
    M = np.dot(x, x.T)  # Could also use np.cov(x) here.
    return ctr, svd(M)[0][:,1]

0 个答案:

没有答案