docstr: Compute the correlation (matrix) for the input RDD(s) using the
  specified method.
  Methods currently supported: `pearson (default), spearman`.
  
  If a single RDD of Vectors is passed in, a correlation matrix
  comparing the columns in the input RDD is returned. Use `method`
  to specify the method to be used for single RDD inout.
  If two RDDs of floats are passed in, a single float is returned.
  
  Parameters
  ----------
  x : :py:class:`pyspark.RDD`
      an RDD of vector for which the correlation matrix is to be computed,
      or an RDD of float of the same cardinality as y when y is specified.
  y : :py:class:`pyspark.RDD`, optional
      an RDD of float of the same cardinality as x.
  method : str, optional
      String specifying the method to use for computing correlation.
      Supported: `pearson` (default), `spearman`
  
  Returns
  -------
  :py:class:`pyspark.mllib.linalg.Matrix`
      Correlation matrix comparing columns in x.
  
  Examples
  --------
  >>> x = sc.parallelize([1.0, 0.0, -2.0], 2)
  >>> y = sc.parallelize([4.0, 5.0, 3.0], 2)
  >>> zeros = sc.parallelize([0.0, 0.0, 0.0], 2)
  >>> abs(Statistics.corr(x, y) - 0.6546537) < 1e-7
  True
  >>> Statistics.corr(x, y) == Statistics.corr(x, y, "pearson")
  True
  >>> Statistics.corr(x, y, "spearman")
  0.5
  >>> from math import isnan
  >>> isnan(Statistics.corr(x, zeros))
  True
  >>> from pyspark.mllib.linalg import Vectors
  >>> rdd = sc.parallelize([Vectors.dense([1, 0, 0, -2]), Vectors.dense([4, 5, 0, 3]),
  ...                       Vectors.dense([6, 7, 0,  8]), Vectors.dense([9, 0, 0, 1])])
  >>> pearsonCorr = Statistics.corr(rdd)
  >>> print(str(pearsonCorr).replace('nan', 'NaN'))
  [[ 1.          0.05564149         NaN  0.40047142]
   [ 0.05564149  1.                 NaN  0.91359586]
   [        NaN         NaN  1.                 NaN]
   [ 0.40047142  0.91359586         NaN  1.        ]]
  >>> spearmanCorr = Statistics.corr(rdd, method="spearman")
  >>> print(str(spearmanCorr).replace('nan', 'NaN'))
  [[ 1.          0.10540926         NaN  0.4       ]
   [ 0.10540926  1.                 NaN  0.9486833 ]
   [        NaN         NaN  1.                 NaN]
   [ 0.4         0.9486833          NaN  1.        ]]
  >>> try:
  ...     Statistics.corr(rdd, "spearman")
  ...     print("Method name as second argument without 'method=' shouldn't be allowed.")
  ... except TypeError:
  ...     pass
docstr_tok: ["Compute","the","correlation","(","matrix",")","for","the","input","RDD","(","s",")","using","the","specified","method",".","Methods","currently","supported",":","`","pearson","(","default",")",",","spearman","`",".","If","a","single","RDD","of","Vectors","is","passed","in",",","a","correlation","matrix","comparing","the","columns","in","the","input","RDD","is","returned",".","Use","`","method","`","to","specify","the","method","to","be","used","for","single","RDD","inout",".","If","two","RDDs","of","floats","are","passed","in",",","a","single","float","is","returned",".","Parameters","--","--","--","--","--","x",":",":","py",":","class",":","`","pyspark.RDD","`","an","RDD","of","vector","for","which","the","correlation","matrix","is","to","be","computed",",","or","an","RDD","of","float","of","the","same","cardinality","as","y","when","y","is","specified",".","y",":",":","py",":","class",":","`","pyspark.RDD","`",",","optional","an","RDD","of","float","of","the","same","cardinality","as","x.","method",":","str",",","optional","String","specifying","the","method","to","use","for","computing","correlation",".","Supported",":","`","pearson","`","(","default",")",",","`","spearman","`","Returns","--","--","--","-",":","py",":","class",":","`","pyspark.mllib.linalg.Matrix","`","Correlation","matrix","comparing","columns","in","x",".","Examples","--","--","--","--",">",">",">","x","=","sc.parallelize","(","[","1.0",",","0.0",",","-2.0","]",",","2",")",">",">",">","y","=","sc.parallelize","(","[","4.0",",","5.0",",","3.0","]",",","2",")",">",">",">","zeros","=","sc.parallelize","(","[","0.0",",","0.0",",","0.0","]",",","2",")",">",">",">","abs","(","Statistics.corr","(","x",",","y",")","-","0.6546537",")","<","1e-7","True",">",">",">","Statistics.corr","(","x",",","y",")","==","Statistics.corr","(","x",",","y",",","``","pearson","''",")","True",">",">",">","Statistics.corr","(","x",",","y",",","``","spearman","''",")","0.5",">",">",">","from","math","import","isnan",">",">",">","isnan","(","Statistics.corr","(","x",",","zeros",")",")","True",">",">",">","from","pyspark.mllib.linalg","import","Vectors",">",">",">","rdd","=","sc.parallelize","(","[","Vectors.dense","(","[","1",",","0",",","0",",","-2","]",")",",","Vectors.dense","(","[","4",",","5",",","0",",","3","]",")",",","...","Vectors.dense","(","[","6",",","7",",","0",",","8","]",")",",","Vectors.dense","(","[","9",",","0",",","0",",","1","]",")","]",")",">",">",">","pearsonCorr","=","Statistics.corr","(","rdd",")",">",">",">","print","(","str","(","pearsonCorr",")",".replace","(","'nan","'",",","'NaN","'",")",")","[","[","1",".","0.05564149","NaN","0.40047142","]","[","0.05564149","1",".","NaN","0.91359586","]","[","NaN","NaN","1",".","NaN","]","[","0.40047142","0.91359586","NaN","1",".","]","]",">",">",">","spearmanCorr","=","Statistics.corr","(","rdd",",","method=","''","spearman","''",")",">",">",">","print","(","str","(","spearmanCorr",")",".replace","(","'nan","'",",","'NaN","'",")",")","[","[","1",".","0.10540926","NaN","0.4","]","[","0.10540926","1",".","NaN","0.9486833","]","[","NaN","NaN","1",".","NaN","]","[","0.4","0.9486833","NaN","1",".","]","]",">",">",">","try",":","...","Statistics.corr","(","rdd",",","``","spearman","''",")","...","print","(","``","Method","name","as","second","argument","without","'method=","'","should","n't","be","allowed",".","''",")","...","except","TypeError",":","...","pass"]
code: def corr(
      x: Union[RDD[Vector], RDD[float]],
      y: Optional[RDD[float]] = None,
      method: Optional["CorrMethodType"] = None,
  ) -> Union[float, Matrix]:
      """
      Compute the correlation (matrix) for the input RDD(s) using the
      specified method.
      Methods currently supported: `pearson (default), spearman`.
  
      If a single RDD of Vectors is passed in, a correlation matrix
      comparing the columns in the input RDD is returned. Use `method`
      to specify the method to be used for single RDD inout.
      If two RDDs of floats are passed in, a single float is returned.
  
      Parameters
      ----------
      x : :py:class:`pyspark.RDD`
          an RDD of vector for which the correlation matrix is to be computed,
          or an RDD of float of the same cardinality as y when y is specified.
      y : :py:class:`pyspark.RDD`, optional
          an RDD of float of the same cardinality as x.
      method : str, optional
          String specifying the method to use for computing correlation.
          Supported: `pearson` (default), `spearman`
  
      Returns
      -------
      :py:class:`pyspark.mllib.linalg.Matrix`
          Correlation matrix comparing columns in x.
  
      Examples
      --------
      >>> x = sc.parallelize([1.0, 0.0, -2.0], 2)
      >>> y = sc.parallelize([4.0, 5.0, 3.0], 2)
      >>> zeros = sc.parallelize([0.0, 0.0, 0.0], 2)
      >>> abs(Statistics.corr(x, y) - 0.6546537) < 1e-7
      True
      >>> Statistics.corr(x, y) == Statistics.corr(x, y, "pearson")
      True
      >>> Statistics.corr(x, y, "spearman")
      0.5
      >>> from math import isnan
      >>> isnan(Statistics.corr(x, zeros))
      True
      >>> from pyspark.mllib.linalg import Vectors
      >>> rdd = sc.parallelize([Vectors.dense([1, 0, 0, -2]), Vectors.dense([4, 5, 0, 3]),
      ...                       Vectors.dense([6, 7, 0,  8]), Vectors.dense([9, 0, 0, 1])])
      >>> pearsonCorr = Statistics.corr(rdd)
      >>> print(str(pearsonCorr).replace('nan', 'NaN'))
      [[ 1.          0.05564149         NaN  0.40047142]
       [ 0.05564149  1.                 NaN  0.91359586]
       [        NaN         NaN  1.                 NaN]
       [ 0.40047142  0.91359586         NaN  1.        ]]
      >>> spearmanCorr = Statistics.corr(rdd, method="spearman")
      >>> print(str(spearmanCorr).replace('nan', 'NaN'))
      [[ 1.          0.10540926         NaN  0.4       ]
       [ 0.10540926  1.                 NaN  0.9486833 ]
       [        NaN         NaN  1.                 NaN]
       [ 0.4         0.9486833          NaN  1.        ]]
      >>> try:
      ...     Statistics.corr(rdd, "spearman")
      ...     print("Method name as second argument without 'method=' shouldn't be allowed.")
      ... except TypeError:
      ...     pass
      """
      # Check inputs to determine whether a single value or a matrix is needed for output.
      # Since it's legal for users to use the method name as the second argument, we need to
      # check if y is used to specify the method name instead.
      if type(y) == str:
          raise TypeError("Use 'method=' to specify method name.")
  
      if not y:
          return cast(
              JavaObject,
              callMLlibFunc("corr", x.map(_convert_to_vector), method),
          ).toArray()
      else:
          return cast(
              float,
              callMLlibFunc(
                  "corr",
                  cast(RDD[float], x).map(float),
                  y.map(float),
                  method,
              ),
          )
  
imports: import sys
  from typing import cast, overload, List, Optional, TYPE_CHECKING, Union
  from numpy import ndarray
  from py4j.java_gateway import JavaObject
  from pyspark.rdd import RDD
  from pyspark.mllib.common import callMLlibFunc, JavaModelWrapper
  from pyspark.mllib.linalg import Matrix, Vector, _convert_to_vector
  from pyspark.mllib.regression import LabeledPoint
  from pyspark.mllib.stat.test import ChiSqTestResult, KolmogorovSmirnovTestResult
label_desc: Use image node_id 4 for calling the Statistics obj's underlying member method code with example usage: obj.corr(x, y, method) and returns: cast, cast