code: def density(w, **kwargs):
      """Compute density of a sparse vector
  
      Return a value between 0 and 1
      """
      if hasattr(w, "toarray"):
          d = float(w.nnz) / (w.shape[0] * w.shape[1])
      else:
          d = 0 if w is None else float((w != 0).sum()) / w.size
      return d
  
imports: from __future__ import division
  from functools import partial
  import warnings
  import numpy
  from scipy import linalg
  from scipy.sparse import issparse, csr_matrix
  from .None import check_random_state
  from .fixes import np_version
  from ._logistic_sigmoid import _log_logistic_sigmoid
  from ..externals.six.moves import xrange
  from .sparsefuncs_fast import csr_row_norms
  from .validation import check_array
  from ..exceptions import NonBLASDotWarning
label_desc: Use image node_id 8 for calling a global function with example usage: density(w) and returns: d