- Cubic.create_adjacency_matrix(weights=None, fmt='coo', triu=False, drop_zeros=False)¶
Generates a weighted adjacency matrix in the desired sparse format
weights (array_like, optional) –
An array containing the throat values to enter into the matrix (in graph theory these are known as the ‘weights’).
If the array is Nt-long, it implies that the matrix is symmetric, so the upper and lower triangular regions are mirror images. If it is 2*Nt-long then it is assumed that the first Nt elements are for the upper triangle, and the last Nt element are for the lower triangular.
If omitted, ones are used to create a standard adjacency matrix representing connectivity only.
fmt (str, optional) –
- The sparse storage format to return. Options are:
’coo’ : This is the native format of OpenPNM’s data ‘lil’ : Enables row-wise slice of the matrix ‘csr’ : Favored by most linear algebra routines ‘dok’ : Enables subscript access of locations
triu (bool, default is
False) – If
True, the returned sparse matrix only contains the upper-triangular elements. This argument is ignored if the
weightsarray is 2*Nt-long.
drop_zeros (bool, default is
False) – If
True, applies the
eliminate_zerosmethod of the sparse array to remove all zero locations.
- Return type
An adjacency matrix in the specified Scipy sparse format.
The adjacency matrix is used by OpenPNM for finding the pores connected to a give pore or set of pores. Specifically, an adjacency matrix has Np rows and Np columns. Each row represents a pore, containing non-zero values at the locations corresponding to the indices of the pores connected to that pore. The
weightsargument indicates what value to place at each location, with the default being 1’s to simply indicate connections. Another useful option is throat indices, such that the data values on each row indicate which throats are connected to the pore.
>>> import openpnm as op >>> pn = op.network.Cubic(shape=[5, 5, 5]) >>> weights = np.random.rand(pn.num_throats(), ) < 0.5 >>> am = pn.create_adjacency_matrix(weights=weights, fmt='csr')