I found this solution concatenate empty array, but I don't believe it fully addresses my issue. I want a more general approach that avoids adding an if statement to every instance of concatenation. Several functions within a MATLAB script that I'm transcribing into Python come after an if statement that initializes FixedDictionaryElement
, which is a 2-D array.
if (param.preserveDCAtom>0)
FixedDictionaryElement(1:size(Data,1),1) = 1/sqrt(size(Data,1));
else
FixedDictionaryElement = [];
If this condition is met, a 2-d array is initialized, filled with data, and later concatenated with another 2-D array in several different places; however, if the condition isn't met, an empty array is initialized FixedDictionaryElement = []
, but it's still concatenated in the same places like the example I've given below. I assume MATLAB is simply concatenating the empty array, which ends up being like multiplying a number by 1. The filled array is unaffected by the empty array, and the program continues unabated. FixedDictionaryElement
is the empty array in this case.
if (param.errorFlag==0)
CoefMatrix = OMP(**[FixedDictionaryElement,Dictionary]**,Data, param.L);
Assume FixedDictionaryElement = []
and Dictionary = 34x80
.
From looking at the MATLAB code, I assume the empty array is initialized to allow for the concatenation to be done throughout the script, irrespective of the result of the if statement. Otherwise, you'd get an error that FixedDictionaryElement
is undefined without the empty array.
How can I generalize the solution given in the above link without putting a new if statement at every instance of concatenation?