New answers tagged

3

Another way data = {{1, 1, 1}, {2, 1, 2}, {2, 2, 5}, {2, 3, 3}, {2, 4, 4}, {2, 6, 1}, {3, 2, 3}, {3, 3, 3}, {3, 4, 12}, {3, 6, 7}, {4, 4, 4}, {4, 6, 6}, {5, 6, 1}}; dims = Max /@ Transpose@data[[;; , ;; 2]] mat = ConstantArray[0, dims]; (mat[[#1, #2]] = #3) & @@@ data; mat {5,6} {{1, 0, 0, 0, 0, 0}, {2, 5, 3, 4, 0, 1}, {0, 3, 3, 12, 0, 7}, {0, ...


11

This is precisely what SparseArray is good for: SparseArray[data[[All, 1 ;; 2]] -> data[[All, 3]]]


Top 50 recent answers are included