parameters: (matrix: Union[core.Matrix, core.Vector], copy: bool = True, dense: bool = False)
docstring: Converts a Psi4 Matrix or Vector to a NumPy array. Either copies the data or simply
      constructs a view.
  
      Parameters
      ----------
      matrix
          Pointers to which Psi4 core class should be used in the construction.
      copy
          Copy the data if `True`, return a view otherwise
      dense
          Converts irreped Psi4 objects to diagonally blocked dense arrays if `True`. Returns a list of arrays otherwise.
  
      Returns
      -------
      numpy.ndarray
         Returns either a list of np.array's or the base array depending on options.
  
      Notes
      -----
      This is a generalized function to convert a Psi4 object to a NumPy array
  
      Examples
      --------
  
      >>> data = psi4.core.Matrix(3, 3)
      >>> data.to_array()
      [[ 0.  0.  0.]
       [ 0.  0.  0.]
       [ 0.  0.  0.]]
docstring_summary: Converts a Psi4 Matrix or Vector to a NumPy array. Either copies the data or simply
      constructs a view.
docstring_tokens: Converts a Psi4 Matrix or Vector to a NumPy array . Either copies the data or simply constructs a view .
function: def _to_array(matrix: Union[core.Matrix, core.Vector], copy: bool = True, dense: bool = False) -> Union[np.ndarray, List[np.ndarray]]:
      """
      Converts a Psi4 Matrix or Vector to a NumPy array. Either copies the data or simply
      constructs a view.
  
      Parameters
      ----------
      matrix
          Pointers to which Psi4 core class should be used in the construction.
      copy
          Copy the data if `True`, return a view otherwise
      dense
          Converts irreped Psi4 objects to diagonally blocked dense arrays if `True`. Returns a list of arrays otherwise.
  
      Returns
      -------
      numpy.ndarray
         Returns either a list of np.array's or the base array depending on options.
  
      Notes
      -----
      This is a generalized function to convert a Psi4 object to a NumPy array
  
      Examples
      --------
  
      >>> data = psi4.core.Matrix(3, 3)
      >>> data.to_array()
      [[ 0.  0.  0.]
       [ 0.  0.  0.]
       [ 0.  0.  0.]]
      """
      if matrix.nirrep() > 1:
  
          # We will copy when we make a large matrix
          if dense:
              copy = False
  
          matrix_views = _get_raw_views(matrix, copy=copy)
  
          # Return the list of arrays
          if dense is False:
              return matrix_views
  
          # Build the dense matrix
          if isinstance(matrix, core.Vector):
              ret_type = '1D'
          elif isinstance(matrix, core.Matrix):
              ret_type = '2D'
          else:
              raise ValidationError("Array_to_Matrix: type '%s' is not recognized." % type(matrix))
  
          dim1 = []
          dim2 = []
          for h in matrix_views:
              # Ignore zero dim irreps
              if 0 in h.shape:
                  dim1.append(0)
                  dim2.append(0)
              else:
                  dim1.append(h.shape[0])
                  if ret_type == '2D':
                      dim2.append(h.shape[1])
  
          ndim1 = np.sum(dim1)
          ndim2 = np.sum(dim2)
          if ret_type == '1D':
              dense_ret = np.zeros(shape=(ndim1))
              start = 0
              for d1, arr in zip(dim1, matrix_views):
                  if d1 == 0: continue
                  dense_ret[start:start + d1] = arr
                  start += d1
          else:
              dense_ret = np.zeros(shape=(ndim1, ndim2))
              start1 = 0
              start2 = 0
              for d1, d2, arr in zip(dim1, dim2, matrix_views):
                  if (d1 == 0) or (d2 == 0): continue
  
                  dense_ret[start1:start1 + d1, start2:start2 + d2] = arr
                  start1 += d1
                  start2 += d2
  
          return dense_ret
  
      else:
          return _get_raw_views(matrix, copy=copy)[0]
function_tokens: def _to_array ( matrix : Union [ core . Matrix , core . Vector ] , copy : bool = True , dense : bool = False ) -> Union [ np . ndarray , List [ np . ndarray ] ] : if matrix . nirrep ( ) > 1 : # We will copy when we make a large matrix if dense : copy = False matrix_views = _get_raw_views ( matrix , copy = copy ) # Return the list of arrays if dense is False : return matrix_views # Build the dense matrix if isinstance ( matrix , core . Vector ) : ret_type = '1D' elif isinstance ( matrix , core . Matrix ) : ret_type = '2D' else : raise ValidationError ( "Array_to_Matrix: type '%s' is not recognized." % type ( matrix ) ) dim1 = [ ] dim2 = [ ] for h in matrix_views : # Ignore zero dim irreps if 0 in h . shape : dim1 . append ( 0 ) dim2 . append ( 0 ) else : dim1 . append ( h . shape [ 0 ] ) if ret_type == '2D' : dim2 . append ( h . shape [ 1 ] ) ndim1 = np . sum ( dim1 ) ndim2 = np . sum ( dim2 ) if ret_type == '1D' : dense_ret = np . zeros ( shape = ( ndim1 ) ) start = 0 for d1 , arr in zip ( dim1 , matrix_views ) : if d1 == 0 : continue dense_ret [ start : start + d1 ] = arr start += d1 else : dense_ret = np . zeros ( shape = ( ndim1 , ndim2 ) ) start1 = 0 start2 = 0 for d1 , d2 , arr in zip ( dim1 , dim2 , matrix_views ) : if ( d1 == 0 ) or ( d2 == 0 ) : continue dense_ret [ start1 : start1 + d1 , start2 : start2 + d2 ] = arr start1 += d1 start2 += d2 return dense_ret else : return _get_raw_views ( matrix , copy = copy ) [ 0 ]