Main Content

zipWithIndex

Class: matlab.compiler.mlspark.RDD
Namespace: matlab.compiler.mlspark

Zip an RDD with its element indices

Syntax

result = zipWithIndex(obj)

Description

result = zipWithIndex(obj) zips an obj with its element indices.

Input Arguments

expand all

An input RDD, specified as a RDD object.

Output Arguments

expand all

An output pipelined RDD, returned as a RDD object.

Examples

expand all

%% Connect to Spark
sparkProp = containers.Map({'spark.executor.cores'}, {'1'});
conf = matlab.compiler.mlspark.SparkConf('AppName','myApp', ...
                        'Master','local[1]','SparkProperties',sparkProp);
sc = matlab.compiler.mlspark.SparkContext(conf);

%% zipWithIndex
x = sc.parallelize({'a','b','c','d'},3);
out = x.zipWithIndex().collect(); % {{'a',0},{'b',1},{'c',2},{'d',3}}

Version History

Introduced in R2016b