我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用scipy.sparse.bsr_matrix()。
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")
def sparse_bsr_matrices(): bsr = sparse.bsr_matrix([[i, j, k], [l, m, n], [p, q, r]]) #print "bsr matrices =" #print bsr return bsr
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)
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)
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]])