create_incidence_matrix#

Demo.create_incidence_matrix(weights=None, fmt='coo', drop_zeros=False)#

Creates a weighted incidence matrix in the desired sparse format

Parameters:
  • 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 omitted, ones are used to create a standard incidence matrix representing connectivity only.

  • fmt (str, default is 'coo') –

    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

  • drop_zeros (bool, default is False) – If True, applies the eliminate_zeros method of the sparse array to remove all zero locations.

Returns:

An incidence matrix in the specified sparse format

Return type:

sparse_array

Notes

The incidence matrix is a cousin to the adjacency matrix, and used by OpenPNM for finding the throats connected to a give pore or set of pores. Specifically, an incidence matrix has Np rows and Nt columns, and each row represents a pore, containing non-zero values at the locations corresponding to the indices of the throats connected to that pore. The weights argument 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, though this is redundant as it is identical to the locations of non-zeros.

Examples

>>> import openpnm as op
>>> pn = op.network.Cubic(shape=[5, 5, 5])
>>> weights = np.random.rand(pn.num_throats(), ) < 0.5
>>> im = pn.create_incidence_matrix(weights=weights, fmt='csr')