pyspark.ml.functions.
array_to_vector
Converts a column of array of numeric type into a column of dense vectors in MLlib
New in version 3.1.0.
pyspark.sql.Column
Input column
The converted column of MLlib dense vectors.
Examples
>>> from pyspark.ml.functions import array_to_vector >>> df1 = spark.createDataFrame([([1.5, 2.5],),], schema='v1 array<double>') >>> df1.select(array_to_vector('v1').alias('vec1')).collect() [Row(vec1=DenseVector([1.5, 2.5]))] >>> df2 = spark.createDataFrame([([1.5, 3.5],),], schema='v1 array<float>') >>> df2.select(array_to_vector('v1').alias('vec1')).collect() [Row(vec1=DenseVector([1.5, 3.5]))] >>> df3 = spark.createDataFrame([([1, 3],),], schema='v1 array<int>') >>> df3.select(array_to_vector('v1').alias('vec1')).collect() [Row(vec1=DenseVector([1.0, 3.0]))]