Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change first example for sparse arrays #33189

Merged
merged 1 commit into from
Sep 7, 2019

Conversation

szarnyasg
Copy link
Contributor

Currently, the first example in the SparseArrays docs is the following:

julia> A = sparse([1, 2, 3], [1, 2, 3], [0, 2, 0])
3×3 SparseMatrixCSC{Int64,Int64} with 3 stored entries:
  [1, 1]  =  0
  [2, 2]  =  2
  [3, 3]  =  0

julia> dropzeros(A)
3×3 SparseMatrixCSC{Int64,Int64} with 1 stored entry:
  [2, 2]  =  2

This example is shown before the COO format is explained (and it needs to use COO as it deals with explicitly setting zero values). If a user scans this page superficially - e.g. when looking for a quick example that shows how to initialize a sparse matrix -, they might be inclined to think that the function

sparse([1, 2, 3], [1, 2, 3], [0, 2, 0])

creates a 3x3 matrix of the values listed in the arrays and that way confuse it with

sparse([1 2 3; 1 2 3; 0 2 0])

(The latter syntax is also there on the page, coming from the docstring of findnz).

I have been confused by this multiple times when I forgot the syntax and visited the Sparse Arrays documentation page to refresh my memory. To mitigate this, this PR proposes a simple change and adds an additional non-zero entry, which hopefully makes the docs a bit more instructive.

@ViralBShah ViralBShah merged commit a3ccac0 into JuliaLang:master Sep 7, 2019
@szarnyasg szarnyasg deleted the sparse-docs-example branch September 7, 2019 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants