pyspark.ml.functions.array_to_vector¶
-
pyspark.ml.functions.
array_to_vector
(col: pyspark.sql.column.Column) → pyspark.sql.column.Column¶ Converts a column of array of numeric type into a column of pyspark.ml.linalg.DenseVector instances
- Parameters
- col
pyspark.sql.Column
or str Input column
- col
- Returns
pyspark.sql.Column
The converted column of 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]))]