Esempio n. 1
0
def _sprandn(m, n, density=0.01, format="coo", dtype=None, random_state=None):
    # Helper function for testing.
    if random_state is None:
        random_state = np.random
    elif isinstance(random_state, (int, np.integer)):
        random_state = np.random.RandomState(random_state)
    data_rvs = random_state.randn
    return construct.random(m, n, density, format, dtype, random_state, data_rvs)
Esempio n. 2
0
def _sprandn(m, n, density=0.01, format="coo", dtype=None, random_state=None):
    # Helper function for testing.
    if random_state is None:
        random_state = np.random
    elif isinstance(random_state, (int, np.integer)):
        random_state = np.random.RandomState(random_state)
    data_rvs = random_state.randn
    return construct.random(m, n, density, format, dtype, random_state,
                            data_rvs)
Esempio n. 3
0
 def test_random_sparse_matrix_returns_correct_number_of_non_zero_elements(
         self):
     # A 10 x 10 matrix, with density of 12.65%, should have 13 nonzero elements.
     # 10 x 10 x 0.1265 = 12.65, which should be rounded up to 13, not 12.
     sparse_matrix = construct.random(10, 10, density=0.1265)
     assert_equal(sparse_matrix.count_nonzero(), 13)
Esempio n. 4
0
 def test_random_accept_str_dtype(self):
     # anything that np.dtype can convert to a dtype should be accepted
     # for the dtype
     construct.random(10, 10, dtype='d')
Esempio n. 5
0
def _sprandn(m, n, density=0.01, format="coo", dtype=None, random_state=None):
    # Helper function for testing.
    random_state = check_random_state(random_state)
    data_rvs = random_state.standard_normal
    return construct.random(m, n, density, format, dtype, random_state,
                            data_rvs)
Esempio n. 6
0
 def test_random_accept_str_dtype(self):
     # anything that np.dtype can convert to a dtype should be accepted
     # for the dtype
     a = construct.random(10, 10, dtype='d')
Esempio n. 7
0
# X_2 = np.where(X > 0.6 , 1, 0)
#X = X_1 + X_2

# maintain 0 issue
index = np.where(X==0)
check = index[1]
pair = np.where(check%2==0, check+1, check-1)
newindex = (index[0], pair)
print newindex
X[newindex] = 0





B = sparse.random(p, 1, density=0.1)    # B is random sparse vector
B = B.A
B = np.around(B, decimals=2)
Y_1 = X.dot(B)
Y = np.around(Y_1, decimals=2)

print X.shape
print B.shape
print Y.shape
# Y = np.where(Y_1 > np.median(Y_1, axis=0), 2,1)

# Clustering

# clf = KMeans(n_clusters = k)
# s = clf.fit(Y_1)