To best explain my problem, I will take the following example:
Consider the following matrix :
A = {{1, 2, 3, 4, ""}, {"", 2, 3, 4, ""}, {"", "", 3, 4, ""}, {"", "", "", 4, 5}}
I designed the following two algorithms :
ProjVt[x_, y_, pat_] :=
Block[
{X = x, Y = y, Grid11, Grid21, Resvf1},
Grid11 = PosGrid[X, pat];
Grid21 = ConstantArray["", 10000];
Table[
Table[
Grid21[[ Grid11[[i, j]] ]] = X[[i, Grid11[[i, j]] [[1]] ]],
{j, 1, Length[Grid11[[i]]], 1}
],
{i, 1, Length[X], 1}
];
Resvf1 = Grid21[[1 ;; Length[Y]]]
];
and
ProjHt[x_, y_, pat_] :=
Block[
{X = x, Y = y, Grid12, Grid22, Resvf2},
Grid12 = PosGrid[X, pat];
Grid22 = ConstantArray["", 10000];
Table[
Grid22[[i]] = X[[ i , Grid12[[i, 1, 1]] ;; Grid12[[i, -1, 1]] ]],
{i, 1, Length[X], 1}
];
Resvf2 = DeleteCases[Grid22, ""]
];
The results provided by ProjVt
and ProjHt
in the case of matrix A
are :
Resvf1 = {1,2,3,4,5} Resvf2 = {{1, 2, 3, 4}, {2, 3, 4}, {3, 4}, {4, 5}}
Best known optimization :
ProjHt[X_]:= Map[Select[#, NumberQ] &, X]
ProjVt[X_]:=
Block[
{step1, Res},
step1 = Tranpose[x];
Res = ProjHt[step1][[All,1]]
]
.
DeleteDuplicates@Cases[A, _?NumberQ, {2}]
and as you have already written:Map[Select[#, NumberQ] &, A]
? $\endgroup$Tr(X)
toTr[X]
. Please try making code blocks using the shortcut control/command + k, rather than using ` (backtick) for large code blocks. $\endgroup$A
withX
? :) And thenProjVtalt1[A]
:) So you would needProjVtalt1[mat_]:=DeleteDuplicates[Cases[mat,_?NumberQ,{2}]]
$\endgroup$