当前位置: 首页>>代码示例>>Python>>正文


Python NumpyVectorSpace.from_numpy方法代码示例

本文整理汇总了Python中pymor.vectorarrays.numpy.NumpyVectorSpace.from_numpy方法的典型用法代码示例。如果您正苦于以下问题:Python NumpyVectorSpace.from_numpy方法的具体用法?Python NumpyVectorSpace.from_numpy怎么用?Python NumpyVectorSpace.from_numpy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymor.vectorarrays.numpy.NumpyVectorSpace的用法示例。


在下文中一共展示了NumpyVectorSpace.from_numpy方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_project_array

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_project_array():
    np.random.seed(123)
    U = NumpyVectorSpace.from_numpy(np.random.random((2, 10)))
    basis = NumpyVectorSpace.from_numpy(np.random.random((3, 10)))
    U_p = project_array(U, basis, orthonormal=False)
    onb = gram_schmidt(basis)
    U_p2 = project_array(U, onb, orthonormal=True)
    assert np.all(relative_error(U_p, U_p2) < 1e-10)
开发者ID:tobiasleibner,项目名称:pymor,代码行数:10,代码来源:basic.py

示例2: test_project_array_with_product

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_project_array_with_product():
    np.random.seed(123)
    U = NumpyVectorSpace.from_numpy(np.random.random((1, 10)))
    basis = NumpyVectorSpace.from_numpy(np.random.random((3, 10)))
    product = np.random.random((10, 10))
    product = NumpyMatrixOperator(product.T.dot(product))
    U_p = project_array(U, basis, product=product, orthonormal=False)
    onb = gram_schmidt(basis, product=product)
    U_p2 = project_array(U, onb, product=product, orthonormal=True)
    assert np.all(relative_error(U_p, U_p2, product) < 1e-10)
开发者ID:tobiasleibner,项目名称:pymor,代码行数:12,代码来源:basic.py

示例3: test_axpy

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_axpy():
    x = NumpyVectorSpace.from_numpy(np.array([1.]))
    y = NumpyVectorSpace.from_numpy(np.array([1.]))
    y.axpy(1 + 1j, x)
    assert y.to_numpy()[0, 0] == 2 + 1j

    x = NumpyVectorSpace.from_numpy(np.array([1 + 1j]))
    y = NumpyVectorSpace.from_numpy(np.array([1.]))
    y.axpy(-1, x)
    assert y.to_numpy()[0, 0] == -1j
开发者ID:pymor,项目名称:pymor,代码行数:12,代码来源:complex_values.py

示例4: test_complex

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_complex():
    np.random.seed(0)
    I = np.eye(5)
    A = np.random.randn(5, 5)
    B = np.random.randn(5, 5)
    C = np.random.randn(3, 5)

    Iop = NumpyMatrixOperator(I)
    Aop = NumpyMatrixOperator(A)
    Bop = NumpyMatrixOperator(B)
    Cva = NumpyVectorSpace.from_numpy(C)

    # lincombs
    assert not np.iscomplexobj((Iop * 1 + Bop * 1).assemble().matrix)
    assert not np.iscomplexobj((Aop * 1 + Bop * 1).assemble().matrix)
    assert np.iscomplexobj((Aop * (1+0j) + Bop * (1+0j)).assemble().matrix)
    assert np.iscomplexobj((Aop * 1j + Bop * 1).assemble().matrix)
    assert np.iscomplexobj((Bop * 1 + Aop * 1j).assemble().matrix)

    # apply_inverse
    assert not np.iscomplexobj(Aop.apply_inverse(Cva).to_numpy())
    assert np.iscomplexobj((Aop * 1j).apply_inverse(Cva).to_numpy())
    assert np.iscomplexobj((Aop * 1 + Bop * 1j).assemble().apply_inverse(Cva).to_numpy())
    assert np.iscomplexobj(Aop.apply_inverse(Cva * 1j).to_numpy())

    # append
    for rsrv in (0, 10):
        for o_ind in (slice(None), [0]):
            va = NumpyVectorSpace(5).empty(reserve=rsrv)
            va.append(Cva)
            D = np.random.randn(1, 5) + 1j * np.random.randn(1, 5)
            Dva = NumpyVectorSpace.from_numpy(D)

            assert not np.iscomplexobj(va.to_numpy())
            assert np.iscomplexobj(Dva.to_numpy())
            va.append(Dva[o_ind])
            assert np.iscomplexobj(va.to_numpy())

    # scal
    assert not np.iscomplexobj(Cva.to_numpy())
    assert np.iscomplexobj((Cva * 1j).to_numpy())
    assert np.iscomplexobj((Cva * (1 + 0j)).to_numpy())

    # axpy
    assert not np.iscomplexobj(Cva.to_numpy())
    Cva[0].axpy(1, Dva)
    assert np.iscomplexobj(Cva.to_numpy())

    Cva = NumpyVectorSpace.from_numpy(C)
    assert not np.iscomplexobj(Cva.to_numpy())
    Cva[0].axpy(1j, Dva)
    assert np.iscomplexobj(Cva.to_numpy())
开发者ID:pymor,项目名称:pymor,代码行数:54,代码来源:complex_values.py

示例5: test_scal

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_scal():
    v = np.array([[1, 2, 3],
                  [4, 5, 6]], dtype=float)
    v = NumpyVectorSpace.from_numpy(v)
    v.scal(1j)

    k = 0
    for i in range(2):
        for j in range(3):
            k += 1
            assert v.to_numpy()[i, j] == k * 1j
开发者ID:pymor,项目名称:pymor,代码行数:13,代码来源:complex_values.py

示例6: test_vtkio

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_vtkio(rect_or_tria_grid):
    grid = rect_or_tria_grid
    steps = 4
    for dim in range(1, 2):
        for codim, data in enumerate((NumpyVectorSpace.from_numpy(np.zeros((steps, grid.size(c)))) for c in range(grid.dim+1))):
            with SafeTemporaryFileName('wb') as out_name:
                if codim == 1:
                    with pytest.raises(NotImplementedError):
                        write_vtk(grid, data, out_name, codim=codim)
                else:
                    write_vtk(grid, data, out_name, codim=codim)
开发者ID:tobiasleibner,项目名称:pymor,代码行数:13,代码来源:tools.py

示例7: test_blk_diag_apply_inverse_adjoint

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_blk_diag_apply_inverse_adjoint():
    np.random.seed(0)

    A = np.random.randn(2, 2)
    B = np.random.randn(3, 3)
    C = spla.block_diag(A, B)
    Aop = NumpyMatrixOperator(A)
    Bop = NumpyMatrixOperator(B)
    Cop = BlockDiagonalOperator((Aop, Bop))

    v1 = np.random.randn(2)
    v2 = np.random.randn(3)
    v = np.hstack((v1, v2))
    v1va = NumpyVectorSpace.from_numpy(v1)
    v2va = NumpyVectorSpace.from_numpy(v2)
    vva = BlockVectorSpace.make_array((v1va, v2va))

    wva = Cop.apply_inverse_adjoint(vva)
    w = np.hstack((wva.block(0).to_numpy(), wva.block(1).to_numpy()))
    assert np.allclose(spla.solve(C.T, v), w)
开发者ID:pymor,项目名称:pymor,代码行数:22,代码来源:block.py

示例8: test_real_imag

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_real_imag():
    A = np.array([[1 + 2j, 3 + 4j],
                  [5 + 6j, 7 + 8j],
                  [9 + 10j, 11 + 12j]])
    Ava = NumpyVectorSpace.from_numpy(A)
    Bva = Ava.real
    Cva = Ava.imag

    k = 0
    for i in range(3):
        for j in range(2):
            k += 1
            assert Bva.to_numpy()[i, j] == k
            k += 1
            assert Cva.to_numpy()[i, j] == k
开发者ID:pymor,项目名称:pymor,代码行数:17,代码来源:complex_values.py

示例9: test_apply_adjoint

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_apply_adjoint():
    np.random.seed(0)

    A11 = np.random.randn(2, 3)
    A12 = np.random.randn(2, 4)
    A21 = np.zeros((5, 3))
    A22 = np.random.randn(5, 4)
    A = np.vstack((np.hstack((A11, A12)),
                   np.hstack((A21, A22))))
    A11op = NumpyMatrixOperator(A11)
    A12op = NumpyMatrixOperator(A12)
    A22op = NumpyMatrixOperator(A22)
    Aop = BlockOperator(np.array([[A11op, A12op], [None, A22op]]))

    v1 = np.random.randn(2)
    v2 = np.random.randn(5)
    v = np.hstack((v1, v2))
    v1va = NumpyVectorSpace.from_numpy(v1)
    v2va = NumpyVectorSpace.from_numpy(v2)
    vva = BlockVectorSpace.make_array((v1va, v2va))

    wva = Aop.apply_adjoint(vva)
    w = np.hstack((wva.block(0).to_numpy(), wva.block(1).to_numpy()))
    assert np.allclose(A.T.dot(v), w)
开发者ID:pymor,项目名称:pymor,代码行数:26,代码来源:block.py

示例10: test_pairwise_dot

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_pairwise_dot():
    x = NumpyVectorSpace.from_numpy(np.array([1 + 1j]))
    y = NumpyVectorSpace.from_numpy(np.array([1 - 1j]))
    z = x.pairwise_dot(y)
    assert z == -2j
开发者ID:pymor,项目名称:pymor,代码行数:7,代码来源:complex_values.py

示例11: test_dot

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def test_dot():
    x = NumpyVectorSpace.from_numpy(np.array([1 + 1j]))
    y = NumpyVectorSpace.from_numpy(np.array([1 - 1j]))
    z = x.dot(y)
    assert z[0, 0] == -2j
开发者ID:pymor,项目名称:pymor,代码行数:7,代码来源:complex_values.py

示例12: numpy_vector_array_factory

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def numpy_vector_array_factory(length, dim, seed):
    np.random.seed(seed)
    return NumpyVectorSpace.from_numpy(np.random.random((length, dim)))
开发者ID:pymor,项目名称:pymor,代码行数:5,代码来源:vectorarray.py

示例13: _newton

# 需要导入模块: from pymor.vectorarrays.numpy import NumpyVectorSpace [as 别名]
# 或者: from pymor.vectorarrays.numpy.NumpyVectorSpace import from_numpy [as 别名]
def _newton(order, **kwargs):
    mop = MonomOperator(order)
    rhs = NumpyVectorSpace.from_numpy([0.0])
    guess = NumpyVectorSpace.from_numpy([1.0])
    return newton(mop, rhs, initial_guess=guess, **kwargs)
开发者ID:tobiasleibner,项目名称:pymor,代码行数:7,代码来源:stuff.py


注:本文中的pymor.vectorarrays.numpy.NumpyVectorSpace.from_numpy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。