Reighend
Reighend

Reputation: 124

DenseVector to array list Pyspark ML

I have a variable dense_vector it will print out DenseVector([0.0, 0.0, 0.9998]) when i print it

Is there a way to get only the array [0.0, 0.0, 0.9998]?

Upvotes: 0

Views: 3465

Answers (1)

Mike Scotty
Mike Scotty

Reputation: 10782

In your case - at least according to the docs I found - you should be able to access those values with DenseVector.values.

General answer:

The string representation of an object must not neccassarily reflect the object's content. The data could be stored as a list, tuple, dict, attribute, ... within the class instance, so your best bet is to look at the __str__ / __repr__ implementation and build the list yourself.

Or, if it's your own class, create a method that returns the list, or you could even sub-class the class and then add a method on your own class that returns the list.

Upvotes: 1

Related Questions