pyspark densevector code example
Example 1: spark densevector to list
In your case - at least according to the docs I found
- you should be able to access those values with
DenseVector.values
Example 2: pyspark dense
import pyspark.sql.functions as F
import pyspark.sql.types as T
#or: to_array = F.udf(lambda v: list([float(x) for x in v]), T.ArrayType(T.FloatType()))
to_array = F.udf(lambda v: v.toArray().tolist(), T.ArrayType(T.FloatType()))
df = df.withColumn('features', to_array('features'))