### Install NDimensionalSparseArrays.jl Source: https://github.com/juliasparse/ndimensionalsparsearrays.jl/blob/main/README.md Installs the NDimensionalSparseArrays.jl package using the Julia package manager. ```julia pkg> add NDimensionalSparseArrays ``` -------------------------------- ### Create NDSparseArray instances Source: https://github.com/juliasparse/ndimensionalsparsearrays.jl/blob/main/README.md Demonstrates various methods to create NDSparseArray objects, including empty arrays, from dense arrays, and using specialized constructors like spzeros and spones. ```julia using NDimensionalSparseArrays # Create an empty 3x4x2 sparse array of Float64 A = NDSparseArray{Float64}(3, 4, 2) # Create from a dense array (only non-zero elements are stored) dense_array = [1 0 3; 0 0 0; 2 0 0] B = NDSparseArray(dense_array) # Create a sparse array of zeros C = spzeros(Int, 5, 5) # Create a sparse array of ones D = spones(2, 2) ``` -------------------------------- ### NDSparseArray Sparsity Handling Source: https://github.com/juliasparse/ndimensionalsparsearrays.jl/blob/main/README.md Illustrates functions for inspecting and managing the sparsity of NDSparseArray objects, including counting non-zero elements, calculating sparsity, accessing stored data, and memory compression. ```julia # Get the number of non-zero elements nnz(B) # Get the sparsity of the array (fraction of zero elements) sparsity(B) # Get the stored indices and values indices = stored_indices(B) values = stored_values(B) pairs = stored_pairs(B) # Find the indices and values of non-zero elements (I, V) = findnz(B) # Remove stored zeros to save memory compress!(B) ``` -------------------------------- ### NDSparseArray Arithmetic Operations Source: https://github.com/juliasparse/ndimensionalsparsearrays.jl/blob/main/README.md Demonstrates basic arithmetic operations such as addition, subtraction, and scalar multiplication performed on NDSparseArray objects. ```julia A = NDSparseArray([1 0; 0 4]) B = NDSparseArray([0 2; 3 0]) # Addition C = A + B # [1 2; 3 4] # Subtraction D = A - B # [1 -2; -3 4] # Scalar multiplication E = A * 2 # [2 0; 0 8] ``` -------------------------------- ### Access and Modify NDSparseArray Elements Source: https://github.com/juliasparse/ndimensionalsparsearrays.jl/blob/main/README.md Shows how to set, retrieve, and check for the existence of elements within an NDSparseArray, including using a default value for unset indices. ```julia A = NDSparseArray{Float64}(3, 3) # Set values A[1, 1] = 10.0 A[3, 2] = -5.0 # Get values value = A[1, 1] # returns 10.0 # Check if an index has a stored value hasindex(A, 1, 1) # true hasindex(A, 1, 2) # false # To get a value with a default for unset indices get(A, (1, 2), 0.0) # returns 0.0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.