class_docstr: Internal class for `pyspark.ml.image.ImageSchema` attribute. Meant to be private and
  not to be instantized. Use `pyspark.ml.image.ImageSchema` attribute to access the
  APIs of this class.
class_docstr_tok: ["Internal","class","for","`","pyspark.ml.image.ImageSchema","`","attribute",".","Meant","to","be","private","and","not","to","be","instantized",".","Use","`","pyspark.ml.image.ImageSchema","`","attribute","to","access","the","APIs","of","this","class","."]
docstr: Converts an array with metadata to a two-dimensional image.
  
  Parameters
  ----------
  array : :class:`numpy.ndarray`
      The array to convert to image.
  origin : str
      Path to the image, optional.
  
  Returns
  -------
  :class:`Row`
      that is a two dimensional image.
  
  .. versionadded:: 2.3.0
docstr_tok: ["Converts","an","array","with","metadata","to","a","two-dimensional","image",".","Parameters","--","--","--","--","--","array",":",":","class",":","`","numpy.ndarray","`","The","array","to","convert","to","image",".","origin",":","str","Path","to","the","image",",","optional",".","Returns","--","--","--","-",":","class",":","`","Row","`","that","is","a","two","dimensional","image",".","..","versionadded",":",":","2.3.0"]
code: def toImage(self, array: np.ndarray, origin: str = "") -> Row:
      """
      Converts an array with metadata to a two-dimensional image.
  
      Parameters
      ----------
      array : :class:`numpy.ndarray`
          The array to convert to image.
      origin : str
          Path to the image, optional.
  
      Returns
      -------
      :class:`Row`
          that is a two dimensional image.
  
      .. versionadded:: 2.3.0
      """
  
      if not isinstance(array, np.ndarray):
          raise TypeError(
              "array argument should be numpy.ndarray; however, it got [%s]."
              % type(array)
          )
  
      if array.ndim != 3:
          raise ValueError("Invalid array shape")
  
      height, width, nChannels = array.shape
      ocvTypes = ImageSchema.ocvTypes
      if nChannels == 1:
          mode = ocvTypes["CV_8UC1"]
      elif nChannels == 3:
          mode = ocvTypes["CV_8UC3"]
      elif nChannels == 4:
          mode = ocvTypes["CV_8UC4"]
      else:
          raise ValueError("Invalid number of channels")
  
      data = bytearray(array.astype(dtype=np.uint8).ravel().tobytes())
  
      # Creating new Row with _create_row(), because Row(name = value, ... )
      # orders fields by name, which conflicts with expected schema order
      # when the new DataFrame is created by UDF
      return _create_row(
          self.imageFields,
          [origin, height, width, nChannels, mode, data],
      )
  
file_path: spark/python/pyspark/ml/image.py
imports: import sys
  from typing import Any, Dict, List, NoReturn, Optional, cast
  import numpy
  from pyspark import SparkContext
  from pyspark.sql.types import Row, StructType, _create_row, _parse_datatype_json_string
  from pyspark.sql import SparkSession
label_desc: Use image node_id 8 for calling the _ImageSchema obj's underlying member method code with example usage: obj.toImage(array, origin) and returns: _create_row