@@ -20,13 +20,16 @@ matrix:
20
20
... [0, 1, 2, 3, 4]]
21
21
>>> data = [10, 20, 30, 40, 50]
22
22
>>> s = sparse.COO(coords, data, shape=(5, 5))
23
-
24
- >>> s.todense()
25
- array([[10, 0, 0, 0, 0],
26
- [ 0, 20, 0, 0, 0],
27
- [ 0, 0, 30, 0, 0],
28
- [ 0, 0, 0, 40, 0],
29
- [ 0, 0, 0, 0, 50]])
23
+ >>> s
24
+ <COO: shape=(5, 5), dtype=int64, nnz=5, fill_value=0>
25
+ 0 1 2 3 4
26
+ ┌ ┐
27
+ 0 │ 10 │
28
+ 1 │ 20 │
29
+ 2 │ 30 │
30
+ 3 │ 40 │
31
+ 4 │ 50 │
32
+ └ ┘
30
33
31
34
In general :code:`coords` should be a :code:`(ndim, nnz)` shaped
32
35
array. Each row of :code:`coords` contains one dimension of the
@@ -47,6 +50,15 @@ identity matrix:
47
50
... [0, 1, 2, 3]]
48
51
>>> data = 1
49
52
>>> s = sparse.COO(coords, data, shape=(4, 4))
53
+ >>> s
54
+ <COO: shape=(4, 4), dtype=int64, nnz=4, fill_value=0>
55
+ 0 1 2 3
56
+ ┌ ┐
57
+ 0 │ 1 │
58
+ 1 │ 1 │
59
+ 2 │ 1 │
60
+ 3 │ 1 │
61
+ └ ┘
50
62
51
63
You can, and should, pass in :obj:`numpy.ndarray` objects for
52
64
:code:`coords` and :code:`data`.
@@ -61,9 +73,19 @@ explicitly. For example, if we did the following without the
61
73
62
74
.. code-block:: python
63
75
64
- coords = [[0, 3, 2, 1], [4, 1, 2, 0]]
65
- data = [1, 4, 2, 1]
66
- s = COO(coords, data, shape=(5, 5))
76
+ >>> coords = [[0, 3, 2, 1], [4, 1, 2, 0]]
77
+ >>> data = [1, 4, 2, 1]
78
+ >>> s = COO(coords, data, shape=(5, 5))
79
+ >>> s
80
+ <COO: shape=(5, 5), dtype=int64, nnz=4, fill_value=0>
81
+ 0 1 2 3 4
82
+ ┌ ┐
83
+ 0 │ 1 │
84
+ 1 │ 1 │
85
+ 2 │ 2 │
86
+ 3 │ 4 │
87
+ 4 │ │
88
+ └ ┘
67
89
68
90
:obj:`COO` arrays support arbitrary fill values. Fill values are the "default"
69
91
value, or value to not store. This can be given a value other than zero. For
@@ -73,9 +95,16 @@ with nonzero fill values.
73
95
74
96
.. code-block:: python
75
97
76
- coords = [[0, 1], [1, 0]]
77
- data = [0, 0]
78
- s = COO(coords, data, fill_value=1)
98
+ >>> coords = [[0, 1], [1, 0]]
99
+ >>> data = [0, 0]
100
+ >>> s = COO(coords, data, fill_value=1)
101
+ >>> s
102
+ <COO: shape=(2, 2), dtype=int64, nnz=2, fill_value=1>
103
+ 0 1
104
+ ┌ ┐
105
+ 0 │ 0 │
106
+ 1 │ 0 │
107
+ └ ┘
79
108
80
109
From :std:doc:`Scipy sparse matrices <scipy:reference/generated/scipy.sparse.spmatrix>`
81
110
---------------------------------------------------------------------------------------
0 commit comments