Question: Say you have two Sparse Vectors. As an example:

```
val vec1 = Vectors.sparse(2, List(0), List(1)) // [1, 0]
val vec2 = Vectors.sparse(2, List(1), List(1)) // [0, 1]

```

I want to concatenate these two vectors so that the result is equivalent to:

```
val vec3 = Vectors.sparse(4, List(0, 2), List(1, 1)) // [1, 0, 0, 1]

```

Does Spark have any such convenience method to do this?

Answer: 
If you have the data in a `DataFrame`, then `VectorAssembler` would be the right thing to use. For example:

```
from pyspark.ml.feature import VectorAssembler

dataset = spark.createDataFrame(
    [(0, Vectors.sparse(10, {0: 0.6931, 5: 0.0, 7: 0.5754, 9: 0.2877}), Vectors.sparse(10, {3: 0.2877, 4: 0.6931, 5: 0.0, 6: 0.6931, 8: 0.6931}))],
["label", "userFeatures1", "userFeatures2"])

assembler = VectorAssembler(
    inputCols=["userFeatures1", "userFeatures2"],
    outputCol="features")

output = assembler.transform(dataset)
output.select("features", "label").show(truncate=False)

```

You would get the following output for this:

```
+---------------------------------------------------------------------------+-----+
|features                                                                   |label|
+---------------------------------------------------------------------------+-----+
|(20,[0,7,9,13,14,16,18],    [0.6931,0.5754,0.2877,0.2877,0.6931,0.6931,0.6931])|0|
+---------------------------------------------------------------------------+-----+

```
If your vectors represent different columns of a dataframe, you can use [VectorAssembler](http://spark.apache.org/docs/latest/ml-features.html#vectorassembler). Just need to set setInputcols (your 2 vectors) and Spark will make your wish come true ;)