# Revision history [back]

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False


The difference about sparse matrices and dense matrices is about how it is stored in memory. Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements are stored in a dictionary mapping an index (i,j) to its entry.

Note that, given a matrix M, you can transform it into a dense matrix or a spase matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False


The difference about sparse matrices and dense matrices is about how it is stored in memory. memory (and therefore which algorithm are used).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements are stored in a dictionary mapping an index (i,j) to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about n non-zero entries compared to about n^2 zero entries).

In your case, n^2/2 non-zero entries is too much, so you should better define dense matrices.

Note that, given a matrix M, you can transform it into a dense matrix or a spase sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True
sage: M.is_dense()
False


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False
sage: M.is_dense()
True


The difference about sparse matrices and dense matrices is about how it is stored in memory (and therefore which algorithm are used).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements are stored in a dictionary mapping an index (i,j) to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about n non-zero entries compared to about n^2 zero entries).

In your case, n^2/2 non-zero entries is too much, so you should better define dense matrices.

Note that, given a matrix M, you can transform it into a dense matrix or a sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True
sage: M.is_dense()
False


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False
sage: M.is_dense()
True


The difference about sparse matrices and dense matrices is about how it is stored in memory (and therefore which algorithm are used).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements are stored in a dictionary mapping an index (i,j) to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about n non-zero entries compared to about n^2 zero entries).

In your case, n^2/2 non-zero entries is too much, so you should better define dense matrices.

Note that, given a matrix M, you can transform it into a dense matrix or a sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True
sage: M.is_dense()
False


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False
sage: M.is_dense()
True


The difference about sparse matrices and dense matrices is about how it is stored in memory (and therefore which algorithm are used).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements are stored in a dictionary mapping an index (i,j) to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about n non-zero entries compared to about n^2 zero entries).

In your case, n^2/2 non-zero entries is too much, so much for the sparse-matrix algorithms to work efficiently. Hence, you should better define dense matrices.

Note that, given a matrix M, you can transform it into a dense matrix or a sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True
sage: M.is_dense()
False


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False
sage: M.is_dense()
True


The difference about sparse matrices and dense matrices is about how it is stored in memory (and therefore which algorithm are used).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements are stored in a dictionary mapping an index (i,j) $(i,j)$ to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about n $n$ non-zero entries compared to about n^2 $n^2$ zero entries).

In your case, n^2/2 $n^2/2$ non-zero entries is too much for the sparse-matrix algorithms to work efficiently. Hence, you should better define dense matrices.

Note that, given a matrix M, M, you can transform it into a dense matrix or a sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True
sage: M.is_dense()
False


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False
sage: M.is_dense()
True


The difference about sparse matrices and dense matrices is about how it is stored in memory (and therefore which algorithm are used).used to handle them).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements are stored in a dictionary mapping an index $(i,j)$ to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about $n$ non-zero entries compared to about $n^2$ zero entries).

In your case, $n^2/2$ non-zero entries is too much for the sparse-matrix algorithms to work efficiently. Hence, you should better define dense matrices.

Note that, given a matrix M, you can transform it into a dense matrix or a sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True
sage: M.is_dense()
False


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False
sage: M.is_dense()
True


The difference about sparse matrices and dense matrices is about how it is stored in memory (and therefore which algorithm are used to handle them).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero elements entries are stored in a dictionary mapping an index $(i,j)$ to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about $n$ non-zero entries compared to about $n^2$ zero entries).

In your case, $n^2/2$ non-zero entries is too much for the sparse-matrix algorithms to work efficiently. Hence, you should better define dense matrices.

Note that, given a matrix M, you can transform it into a dense matrix or a sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.

You should understand that a matrix is not sparse or dense by itself. It depends on how you define it.

For example:

sage: M = matrix(ZZ,[[1,1,1],[1,1,1],[1,1,1]],sparse=True)
sage: M
[1 1 1]
[1 1 1]
[1 1 1]
sage: M.is_sparse()
True
sage: M.is_dense()
False


But

sage: sage: M = matrix(ZZ,3,sparse=False)
sage: M
[0 0 0]
[0 0 0]
[0 0 0]
sage: M.is_sparse()
False
sage: M.is_dense()
True


The difference about sparse matrices and dense matrices is about how it is stored in memory (and therefore which algorithm are used to handle them).

Basically, in a dense matrix, every entry are stored in memory, even if it is zero. In a sparse matrix, only the non-zero entries are stored in a dictionary mapping an index $(i,j)$ to its entry.

So, you should define a matrix as a sparse matrix only if the number of non-zero elements is very small compared to the total number of entries. This is typically useful if the non-zero entries are located along the diagonal (there are about $n$ non-zero entries compared to about $n^2$ zero entries).entries). However, for very small matrices (e.g. 5x5), even with a lot of zero entries, defining dense matrices is usually faster.

In your case, $n^2/2$ non-zero entries is too much for the sparse-matrix algorithms to work efficiently. Hence, you should better define dense matrices.

Note that, given a matrix M, you can transform it into a dense matrix or a sparse matrix with the methods .dense_matrix() and .sparse_matrix(). This can be usefull for example if, after a computation, a lot of entries become non-zero.