<human>:  How to calculate percentage of sparsity for a numpy array/matrix?
<bot>: Here is some code to calculate ratio of sparsity in a numpy array `a`

np.isnan(a).sum() / np.prod(a.shape)

#Warning: this code generation is experimental. Please inspect the code for any bugs before executing.