Python scipy.sparse 模块,bsr_matrix() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用scipy.sparse.bsr_matrix()

项目:smp_base    作者:x75    | 项目源码 | 文件源码
def create_matrix_reservoir(N, p):
    """reservoirs.create_matrix_reservoir

    Create an NxN reservoir recurrence matrix with density p. Wrapper
    for create_matrix_sparse_random.
    """
    # M = spa.rand(N, N, p)
    # M = M.todense()
    # tmp_idx = M != 0
    # tmp = M[tmp_idx]
    # tmp_r = np.random.normal(0, 1, size=(tmp.shape[1],))
    # M[tmp_idx] = tmp_r
    # # return dense representation
    # return np.array(M).copy()
    # # return spa.bsr_matrix(M)

    return create_matrix_sparse_random(N, N, p, dist = "normal")
项目:lazyarray    作者:NeuralEnsemble    | 项目源码 | 文件源码
def sparse_bsr_matrices():
    bsr = sparse.bsr_matrix([[i, j, k], [l, m, n], [p, q, r]])
    #print "bsr matrices ="
    #print bsr
    return bsr
项目:pyculib    作者:numba    | 项目源码 | 文件源码
def bsr_matrix(*args, **kws):
    """Takes the same arguments as ``scipy.sparse.bsr_matrix``.

    Returns a BSR CUDA matrix.
    """
    mat = ss.bsr_matrix(*args, **kws)
    return CudaBSRMatrix().from_host_matrix(mat)
项目:Parallel-SGD    作者:angadgill    | 项目源码 | 文件源码
def test_check_symmetric():
    arr_sym = np.array([[0, 1], [1, 2]])
    arr_bad = np.ones(2)
    arr_asym = np.array([[0, 2], [0, 2]])

    test_arrays = {'dense': arr_asym,
                   'dok': sp.dok_matrix(arr_asym),
                   'csr': sp.csr_matrix(arr_asym),
                   'csc': sp.csc_matrix(arr_asym),
                   'coo': sp.coo_matrix(arr_asym),
                   'lil': sp.lil_matrix(arr_asym),
                   'bsr': sp.bsr_matrix(arr_asym)}

    # check error for bad inputs
    assert_raises(ValueError, check_symmetric, arr_bad)

    # check that asymmetric arrays are properly symmetrized
    for arr_format, arr in test_arrays.items():
        # Check for warnings and errors
        assert_warns(UserWarning, check_symmetric, arr)
        assert_raises(ValueError, check_symmetric, arr, raise_exception=True)

        output = check_symmetric(arr, raise_warning=False)
        if sp.issparse(output):
            assert_equal(output.format, arr_format)
            assert_array_equal(output.toarray(), arr_sym)
        else:
            assert_array_equal(output, arr_sym)
项目:Parallel-SGD    作者:angadgill    | 项目源码 | 文件源码
def test_zero_variance():
    # Test VarianceThreshold with default setting, zero variance.

    for X in [data, csr_matrix(data), csc_matrix(data), bsr_matrix(data)]:
        sel = VarianceThreshold().fit(X)
        assert_array_equal([0, 1, 3, 4], sel.get_support(indices=True))

    assert_raises(ValueError, VarianceThreshold().fit, [[0, 1, 2, 3]])
    assert_raises(ValueError, VarianceThreshold().fit, [[0, 1], [0, 1]])