def make_sparse(arr, kind='block', fill_value=None):
 arr = _sanitize_values(arr)
 if (arr.ndim > 1):
  raise TypeError('expected dimension <= 1 data')
 if (fill_value is None):
  fill_value = na_value_for_dtype(arr.dtype)
 if isnull(fill_value):
  mask = notnull(arr)
 else:
  mask = (arr != fill_value)
 length = len(arr)
 if (length != mask.size):
  indices = mask.sp_index.indices
 else:
  indices = np.arange(length, dtype=np.int32)[mask]
 index = _make_index(length, indices, kind)
 sparsified_values = arr[mask]
 return (sparsified_values, index, fill_value)

def make_sparse ( arr , kind = 'block' , fill_value = None ) : arr = _sanitize_values ( arr ) if ( arr . ndim > 1 ) : raise TypeError ( 'expected dimension <= 1 data' ) if ( fill_value is None ) : fill_value = na_value_for_dtype ( arr . dtype ) if isnull ( fill_value ) : mask = notnull ( arr ) else : mask = ( arr != fill_value ) length = len ( arr ) if ( length != mask . size ) : indices = mask . sp_index . indices else : indices = np . arange ( length , dtype = np . int32 ) [ mask ] index = _make_index ( length , indices , kind ) sparsified_values = arr [ mask ] return ( sparsified_values , index , fill_value )
convert ndarray to sparse format parameters arr : ndarray kind : {block .