Skip to content

Commit

Permalink
scipy sparse matrices to arrays (closes #6) (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdewitt authored Sep 20, 2024
1 parent cf00195 commit ca53eaf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions binarymap/binarymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ class BinaryMap:
Length of the binary representation of each variant.
nvariants : int
Number of variants.
binary_variants : scipy.sparse.csr_matrix of dtype int8
Sparse matrix of shape `nvariants` by `binarylength`. Row
binary_variants : scipy.sparse.csr_array of dtype int8
Sparse array of shape `nvariants` by `binarylength`. Row
`binary_variants[ivariant]` gives the binary representation of
variant `ivariant`, and `binary_variants[ivariant, i]` is 1
if the variant has the substitution :meth:`BinaryMap.i_to_sub`
and 0 otherwise. To convert to dense `numpy.ndarray`, use
`toarray` method of the sparse matrix.
`toarray` method of the sparse array.
binary_sites : numpy.ndarray
Array of length `binarylength` giving the site number corresponding
to each mutation in the binary order. Entries or int or str depending
Expand Down Expand Up @@ -196,7 +196,7 @@ class BinaryMap:
array([ 0. , -0.2 , -0.4 , 0.01, -0.05, -1.2 ])
>>> binmap.func_scores_var
array([0.2 , 0.1 , 0.3 , 0.15, 0.1 , 0.4 ])
>>> type(binmap.binary_variants) == scipy.sparse.csr_matrix
>>> type(binmap.binary_variants) == scipy.sparse.csr_array
True
>>> binmap.binary_variants.toarray()
array([[0, 0, 0, 0, 0],
Expand Down Expand Up @@ -351,7 +351,7 @@ class BinaryMap:
['M1A', 'M1C', 'A2C', 'A2*', 'K3A', 'L3aT']
>>> bmap_sitestr.binary_sites
array(['1', '1', '2', '2', '3', '3a'], dtype='<U2')
>>> type(bmap_sitestr.binary_variants) == scipy.sparse.csr_matrix
>>> type(bmap_sitestr.binary_variants) == scipy.sparse.csr_array
True
>>> bmap_sitestr.binary_variants.toarray()
array([[0, 0, 0, 0, 0, 0],
Expand Down Expand Up @@ -394,7 +394,7 @@ def __eq__(self, other):
elif isinstance(val, numpy.ndarray):
if not numpy.array_equal(val, val2):
return False
elif isinstance(val, scipy.sparse.csr_matrix):
elif isinstance(val, scipy.sparse.csr_array):
if (val - val2).nnz:
return False
elif isinstance(val, (pd.DataFrame, pd.Series)):
Expand Down Expand Up @@ -558,7 +558,7 @@ def __init__(
for isub in self.sub_str_to_indices(subs):
row_ind.append(ivariant)
col_ind.append(isub)
self.binary_variants = scipy.sparse.csr_matrix(
self.binary_variants = scipy.sparse.csr_array(
(numpy.ones(len(row_ind), dtype="int8"), (row_ind, col_ind)),
shape=(self.nvariants, self.binarylength),
dtype="int8",
Expand Down

0 comments on commit ca53eaf

Please sign in to comment.