You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by janardhan shetty <ja...@gmail.com> on 2016/11/14 04:20:58 UTC

Convert SparseVector column to Densevector column

Hi,

Is there any easy way of converting a dataframe column from SparseVector to
DenseVector  using

import org.apache.spark.ml.linalg.DenseVector API ?

Spark ML 2.0

Re: Convert SparseVector column to Densevector column

Posted by janardhan shetty <ja...@gmail.com>.
This worked thanks Maropu.

On Sun, Nov 13, 2016 at 9:34 PM, Takeshi Yamamuro <li...@gmail.com>
wrote:

> Hi,
>
> How about this?
>
> import org.apache.spark.ml.linalg._
> val toSV = udf((v: Vector) => v.toDense)
> val df = Seq((0.1, Vectors.sparse(16, Array(0, 3), Array(0.1, 0.3))),
> (0.2, Vectors.sparse(16, Array(0, 3), Array(0.1, 0.3)))).toDF("a", "b")
> df.select(toSV($"b"))
>
> // maropu
>
>
> On Mon, Nov 14, 2016 at 1:20 PM, janardhan shetty <ja...@gmail.com>
> wrote:
>
>> Hi,
>>
>> Is there any easy way of converting a dataframe column from SparseVector
>> to DenseVector  using
>>
>> import org.apache.spark.ml.linalg.DenseVector API ?
>>
>> Spark ML 2.0
>>
>
>
>
> --
> ---
> Takeshi Yamamuro
>

Re: Convert SparseVector column to Densevector column

Posted by Takeshi Yamamuro <li...@gmail.com>.
Hi,

How about this?

import org.apache.spark.ml.linalg._
val toSV = udf((v: Vector) => v.toDense)
val df = Seq((0.1, Vectors.sparse(16, Array(0, 3), Array(0.1, 0.3))), (0.2,
Vectors.sparse(16, Array(0, 3), Array(0.1, 0.3)))).toDF("a", "b")
df.select(toSV($"b"))

// maropu


On Mon, Nov 14, 2016 at 1:20 PM, janardhan shetty <ja...@gmail.com>
wrote:

> Hi,
>
> Is there any easy way of converting a dataframe column from SparseVector
> to DenseVector  using
>
> import org.apache.spark.ml.linalg.DenseVector API ?
>
> Spark ML 2.0
>



-- 
---
Takeshi Yamamuro