parameters: (self)
return_statement: return result
docstring: Converts the instance's data to a NumPy array.
docstring_summary: Converts the instance's data to a NumPy array.
docstring_tokens: Converts the instance s data to a NumPy array .
function: def asarray(self):
          '''
          Converts the instance's data to a NumPy array.
          '''
          import cntk
          result = None
          if isinstance(self, cntk.Constant):
              ndav = super(cntk.Constant, self).value()
              is_sparse = ndav.is_sparse()
          elif isinstance(self, cntk.Parameter):
              ndav = super(cntk.Parameter, self).value()
              is_sparse = ndav.is_sparse()
          elif isinstance(self, (cntk.cntk_py.Constant, cntk.cntk_py.Parameter)):
              ndav = self.value()
              is_sparse = ndav.is_sparse()
  
          elif isinstance(self, (cntk.cntk_py.NDArrayView, cntk.cntk_py.NDMask)):
              ndav = self
              if isinstance(self, cntk.NDArrayView):
                  is_sparse = ndav.is_sparse
              elif isinstance(self, cntk.cntk_py.NDArrayView):
                  is_sparse = ndav.is_sparse()
              else:
                  is_sparse = False
  
          # Value and MinibatchData have a mask, which means that we need the
          # corresponding Variable to do the proper conversion. For easy
          # discoverability, we nevertheless add asarray() to those classes as
          # well, but issue a warning.
          elif isinstance(self, cntk.cntk_py.Value) or isinstance(self, cntk.cntk_py.MinibatchData):
  
              if isinstance(self, cntk.cntk_py.MinibatchData):
                  value = self.data
              else:
                  value = self
  
              if isinstance(value, cntk.Value):
                  is_sparse = value.is_sparse
                  has_mask = super(cntk.Value, value).mask() is not None
                  ndav = value.data
              else:
                  is_sparse = value.is_sparse()
                  has_mask = value.mask() is not None
                  ndav = value.data()
  
              if has_mask:
                  warnings.warn('asarray() will ignore the mask information. '
                                'Please use as_sequences() to do the proper '
                                'conversion.')
  
          if is_sparse:
              from cntk.internal.sanitize import _sparse_to_dense_network_cache
  
              device = ndav.device
              if callable(device):
                  device = device()
  
              network = _sparse_to_dense_network_cache(ndav.shape[1:], False,
                                                       device)
              warnings.warn('converting Value object to CSR format might be slow')
  
              dense_data = network.eval(self, device=device)
  
              def to_csr(dense_data):
                  if len(dense_data.shape) > 2:
                      warnings.warn('Cannot convert a sparse NDArrayView or Value object '
                                       'with shape %s of rank > 2 to a scipy.csr matrix.'
                                       ' Returning dense data.' % str(dense_data.shape))
                      return dense_data
                  return sparse.csr_matrix(dense_data)
  
              if isinstance(dense_data, list):
                  result = [to_csr(d) for d in dense_data]
              else:
                  result = to_csr(dense_data)
  
          else:
              result = ndav.to_ndarray()
  
          return result
function_tokens: def asarray ( self ) : import cntk result = None if isinstance ( self , cntk . Constant ) : ndav = super ( cntk . Constant , self ) . value ( ) is_sparse = ndav . is_sparse ( ) elif isinstance ( self , cntk . Parameter ) : ndav = super ( cntk . Parameter , self ) . value ( ) is_sparse = ndav . is_sparse ( ) elif isinstance ( self , ( cntk . cntk_py . Constant , cntk . cntk_py . Parameter ) ) : ndav = self . value ( ) is_sparse = ndav . is_sparse ( ) elif isinstance ( self , ( cntk . cntk_py . NDArrayView , cntk . cntk_py . NDMask ) ) : ndav = self if isinstance ( self , cntk . NDArrayView ) : is_sparse = ndav . is_sparse elif isinstance ( self , cntk . cntk_py . NDArrayView ) : is_sparse = ndav . is_sparse ( ) else : is_sparse = False # Value and MinibatchData have a mask, which means that we need the # corresponding Variable to do the proper conversion. For easy # discoverability, we nevertheless add asarray() to those classes as # well, but issue a warning. elif isinstance ( self , cntk . cntk_py . Value ) or isinstance ( self , cntk . cntk_py . MinibatchData ) : if isinstance ( self , cntk . cntk_py . MinibatchData ) : value = self . data else : value = self if isinstance ( value , cntk . Value ) : is_sparse = value . is_sparse has_mask = super ( cntk . Value , value ) . mask ( ) is not None ndav = value . data else : is_sparse = value . is_sparse ( ) has_mask = value . mask ( ) is not None ndav = value . data ( ) if has_mask : warnings . warn ( 'asarray() will ignore the mask information. ' 'Please use as_sequences() to do the proper ' 'conversion.' ) if is_sparse : from cntk . internal . sanitize import _sparse_to_dense_network_cache device = ndav . device if callable ( device ) : device = device ( ) network = _sparse_to_dense_network_cache ( ndav . shape [ 1 : ] , False , device ) warnings . warn ( 'converting Value object to CSR format might be slow' ) dense_data = network . eval ( self , device = device ) def to_csr ( dense_data ) : if len ( dense_data . shape ) > 2 : warnings . warn ( 'Cannot convert a sparse NDArrayView or Value object ' 'with shape %s of rank > 2 to a scipy.csr matrix.' ' Returning dense data.' % str ( dense_data . shape ) ) return dense_data return sparse . csr_matrix ( dense_data ) if isinstance ( dense_data , list ) : result = [ to_csr ( d ) for d in dense_data ] else : result = to_csr ( dense_data ) else : result = ndav . to_ndarray ( ) return result