class_docstr: Initialize weights as sparse matrix.
  
  Parameters
  ----------
  sparsity : float
      Exact fraction of non-zero values per column. Larger values give less
      sparsity.
  std : float
      Non-zero weights are sampled from N(0, std).
class_docstr_tok: ["Initialize","weights","as","sparse","matrix",".","Parameters","--","--","--","--","--","sparsity",":","float","Exact","fraction","of","non-zero","values","per","column",".","Larger","values","give","less","sparsity",".","std",":","float","Non-zero","weights","are","sampled","from","N","(","0",",","std",")","."]
code: def sample(self, shape):
      if len(shape) != 2:
          raise RuntimeError(
              "sparse initializer only works with shapes of length 2"
          )
  
      w = floatX(np.zeros(shape))
      n_inputs, n_outputs = shape
      size = int(
          self.sparsity * n_inputs
      )  # fraction of number of inputs
  
      for k in range(n_outputs):
          indices = np.arange(n_inputs)
          get_rng().shuffle(indices)
          indices = indices[:size]
          values = floatX(get_rng().normal(0.0, self.std, size=size))
          w[indices, k] = values
  
      return w
  
imports: import numpy
  from .utils import floatX
  from .random import get_rng
label_desc: Use image node_id 2 for calling the Sparse obj's underlying member method code with example usage: obj.sample(shape) and returns: w