Array[Int] = Array(0, 1, 0, 2, 1, 0)
我想要一个列表,给我每个条目的索引次数,序列中每个条目的次数。这里的输出是:
Array[Int] = Array(1, 3, 3, 4)
val func1 = (cnt: Int, idx: Int) => Array.fill(cnt)(idx)
countarray.zipWithIndex.map(func1)
func1: (Int, Int) => Array[Int] = <function2>
<console>:132: error: type mismatch;
found : (Int, Int) => Array[Int]
required: ((Int, Int)) => ?
seq_of_vectors.map(_.numNonzeros).zipWithIndex.map(func1)