test_cython.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:dtaidistance 作者: wannesm 项目源码 文件源码
def test_numpymatrix_transpose():
    """Passing a matrix instead of a list failed because the array is now a
    view instead of the original data structure."""
    s = np.matrix([
        [0., 0., 1.,],
        [0, 1, 2],
        [1, 2, 0],
        [2, 0, 0],
        [1, 0, 0],
        [0, 0, 0],
        [1, 0, 0],
        [0, 0, 1],
        [0, 0, 0]
    ]).T
    m = dtw_c.distance_matrix_nogil(s)
    m2 = dtw.distance_matrix(s)
    correct = np.array([
        [np.inf, 1.41421356, 1.73205081],
        [np.inf, np.inf,     1.41421356],
        [np.inf, np.inf,     np.inf]])
    assert m[0, 1] == pytest.approx(math.sqrt(2))
    assert m2[0, 1] == pytest.approx(math.sqrt(2))
    np.testing.assert_almost_equal(correct, m, decimal=4)
    np.testing.assert_almost_equal(correct, m2, decimal=4)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号