docstr: This function do initialize DMatrix from numpy 2D and pandas DataFrame.
  Parameters
docstr_tok: ["This","function","do","initialize","DMatrix","from","numpy","2D","and","pandas","DataFrame",".","Parameters"]
code: def _init_from_npy2d(self, mat, label, field_map):
      """
      This function do initialize DMatrix from numpy 2D and pandas DataFrame.
      Parameters
      """
      if len(mat.shape) != 2:
          raise ValueError("Input numpy.ndarray must be 2 dimensional")
  
      if isinstance(mat, DataFrame):
          mat = mat.values
  
      data = np.array(
          mat.reshape(mat.size), copy=False, dtype=np.float32
      )
      data_ptr = data.ctypes.data_as(ctypes.POINTER(ctypes.c_float))
      label_ptr = None
      field_ptr = None
      if label is not None:
          if isinstance(label, DataFrame):
              label = label.values
          if isinstance(label, Series):
              label = label.values
          if isinstance(label, list):
              label = np.array(label)
          if isinstance(label, ndarray):
              if len(label.shape) > 2:
                  raise ValueError(
                      "Input numpy.ndarray of label must be 1 dimensional or 2 dimensional with one dimensional is 1"
                  )
              if (
                  (len(label.shape) == 2)
                  and (label.shape[0] != 1)
                  and (label.shape[1] != 1)
              ):
                  print(len(label.shape))
                  raise ValueError(
                      "Input numpy.ndarray of label must be 1 dimensional or 2 dimensional with one dimensional is 1"
                  )
              if label.size != mat.shape[0]:
                  raise ValueError(
                      "Input label must has same elements as the data lines"
                  )
              labels = np.array(
                  label.reshape(label.size),
                  copy=False,
                  dtype=np.float32,
              )
              label_ptr = labels.ctypes.data_as(
                  ctypes.POINTER(ctypes.c_float)
              )
          else:
              raise ValueError("Input label must be numpy.ndarray")
  
      if field_map is not None:
          if isinstance(field_map, DataFrame):
              field_map = field_map.values
          if isinstance(field_map, Series):
              field_map = field_map.values
          if isinstance(field_map, list):
              field_map = np.array(field_map)
          if isinstance(field_map, ndarray):
              if len(field_map.shape) > 2:
                  raise ValueError(
                      "Input numpy.ndarray of label must be 1 dimensional or 2 dimensional with one dimensional is 1"
                  )
              if (
                  (len(field_map.shape) == 2)
                  and (field_map.shape[0] != 1)
                  and (label.shape[1] != 1)
              ):
                  raise ValueError(
                      "Input numpy.ndarray of field_map must be 1 dimensional or 2 dimensional with the one dimensional is 1"
                  )
              if field_map.size != mat.shape[1]:
                  raise ValueError(
                      "Input field_map must has same elements as the data columns"
                  )
              fields = np.array(
                  field_map.reshape(field_map.size),
                  copy=False,
                  dtype=np.int32,
              )
              field_ptr = fields.ctypes.data_as(
                  ctypes.POINTER(ctypes.c_uint)
              )
          else:
              raise ValueError("Input of field_map must numpy.ndarray")
  
      _check_call(
          _LIB.XlearnCreateDataFromMat(
              data_ptr,
              ctypes.c_uint64(mat.shape[0]),
              ctypes.c_uint64(mat.shape[1]),
              label_ptr,
              field_ptr,
              ctypes.byref(self.__handle),
          )
      )
  
file_path: xlearn/python-package/xlearn/data.py
imports: import os, ctypes
  from numpy import ndarray
  from .base import DataFrame, Series
  import numpy
  from .base import _LIB, XLearnHandle
  from .base import _check_call, c_str
label_desc: Use image node_id 2 for calling the DMatrix obj's underlying member method code with example usage: obj._init_from_npy2d(mat, label, field_map) without return types