Questions tagged [sparse-array]

In computer science, a sparse array is an array in which most of the elements have the same value (known as the default value—usually 0 or null).

In computer science, a sparse array is an array in which most of the elements have the same value (known as the default value—usually 0 or null).

The occurrence of zero elements in a large array is inefficient for both computation and storage. An array in which there is a large number of zero elements is referred to as being sparse.

In the case of sparse arrays, one can ask for a value from an "empty" array position. If one does this, then for an array of numbers, a value of zero should be returned, and for an array of objects, a value of null should be returned.

A naive implementation of an array may allocate space for the entire array, but in the case where there are few non-default values, this implementation is inefficient. Typically the algorithm used instead of an ordinary array is determined by other known features (or statistical features) of the array. For instance, if the sparsity is known in advance or if the elements are arranged according to some function (e.g., the elements occur in blocks). A heap memory allocator in a program might choose to store regions of blank space in a linked list rather than storing all of the allocated regions in, say a bit array.

Wikipedia: http://en.wikipedia.org/wiki/Sparse_array

94 questions
1
vote
3 answers

Norm of sparse python vectors

Is it possible to effectively obtain the norm of a sparse vector in python? I tried the following: from scipy import sparse from numpy.linalg import norm vector1 = sparse.csr_matrix([ 0 for i in xrange(4000000) ], dtype = float64) #just to test I…
Willian Fuks
  • 11,259
  • 10
  • 50
  • 74
0
votes
1 answer

Unable To Change The Image Resource Of Image Button In A Grid View

The GridView in my app consists of multiple ImageButtons. When an ImageButton is tapped, the image resource of that ImageButton will change. This is the int array of the image resource ids when an ImageButton is not tapped. private final int…
JLT
  • 3,052
  • 9
  • 39
  • 86
0
votes
1 answer

writeSparseArray support SparseArray?

I have a param in SparseArray , and want to serialize it. But the writeSparseArray(Object) for Parcelable seems not support int[]. Is there any other way to serialize the SparseArray,Or only change int[] to Object?
Pitty
  • 329
  • 4
  • 15
0
votes
0 answers

SparseBooleanArray side effects?

I have a ListView in which I could select multiple items. Then, I scan for which ones were actually selected. The following code doesn't bug out on me. SparseBooleanArray checkedNetworks = networksList.getCheckedItemPositions(); if (checkedNetworks…
David
  • 7,028
  • 10
  • 48
  • 95
0
votes
1 answer

Retrieve SparseArray data from model

I have got a model for "DayForecast" containing a SparseArray of another model "WeatherCondition", which has several info about weatherconditions for every 3 hours (so 8 weathercondition models in there). DayForecast.java: public class DayForecast…
Makoto
  • 1,455
  • 4
  • 13
  • 17
0
votes
2 answers

Making SparseArray<> Included ArrayList

i need to make a List of ArrayList , my idea was it: Map> SentReportMap=new HashMap>(); that tell : Use new SparseArray>(...) instead for better performance so , i try this…
Saeid
  • 2,261
  • 4
  • 27
  • 59
0
votes
1 answer

Sort LongSparseArray values

I have a LongSparseArray variable, in which the objects stored implement the interface Comparable. Is there a easy way to sort them, without do it "manually"? I tried Collections.sort(myLongSparseArray), but it does not implements the List…
Daniele Vitali
  • 3,848
  • 8
  • 48
  • 71
0
votes
2 answers

Sampling a matrix in Matlab

I have the sparse Matrix having 300 to 900 rows with 3 columns, I want the sampling of this matrix i.e 20 samples of Matrix of the whole Matrix. How can I sample my matrix MAT in Matlab.
user3396151
0
votes
0 answers

How to create 2D accumulate table in MATLAB?

I want to create a sparse cell that can be used as a 2D accumulate structure. 1 2 3 4 1 [1] [3,2] [2,3,2] [1,2] 2 [1,3] [1,2] [2] [1,4] 3 [2] [1,2] [2,3] [1] The dimension of the matrix is…
SolessChong
  • 3,370
  • 8
  • 40
  • 67
0
votes
1 answer

Submatrix in scipy

I have a sparse matrix A and a column vector a, In[1]: A Out[1]: <256x256 sparse matrix of type '' with 512 stored elements (blocksize = 2x2) in Block Sparse Row format> In[2]: len(a) Out[2]: 70 I would to write a submatrix.…
Ornella
  • 3
  • 2
0
votes
0 answers

Matlab - Create N sparse matrices and sum them

I have N kx1 sparse vectors and I need to multiply each of them by their transpose, creating N square matrices, which I then have to sum over. The desired output is a k by k matrix. I have tried doing this in a loop and using arrayfun, but both…
0
votes
2 answers

matlab: Sparse Function for any matrix

I am trying to write a sparse function code for any matrix size. For example if i have a matrix: A = [ 0 0 0 5 0 2 0 0 1 3 0 0 0 0 4 0]; a=size(A); b=size(A); c=0; position=0; for i=1:a for j=1:b…
user2913990
  • 107
  • 1
  • 1
  • 2
0
votes
4 answers

Java time-efficient sparse 1D array (double)

I need an efficient Java structure to manipulate very sparse vectors of doubles: basic read / write operations. I implemented it in a HashMap but the access is too slow. Should I use another data structure? Do you recommend any free library? Looking…
Marie
  • 1
  • 1
  • 2
0
votes
1 answer

Why does my SparseArray return an ArrayList with zero elements?

I'm iterating through a cursor and populating a SparseArray with ArrayList's containing bundles of information from the cursor: // An ArrayList to hold all of our components per section ArrayList al = new…
IAmKale
  • 3,146
  • 1
  • 25
  • 46
0
votes
1 answer

Automated sparse matricies in Fortran

I know that Intel Fortran has libraries with functions and subroutines for working with sparse matricies, but I'm wondering if there is also some sort of data type or automated method for creating the sparse matricies in the first place. BACKGROUND:…