In Matlab, this type of algorithm (“growing arrays”) is advised against
mine = []
for i=1:100,
mine = [mine,randn(1)]
end
whereas it seems that many examples for Python show this kind of algorithm (this is a really bad example though):
import numpy.random as rand
mine = []
for i in range(100):
mine.append(rand.random(1)[0])
I wonder why that is — what is the difference?
The difference is that:
That said, I think the difference is largely cultural:
ndarraywould be used instead, andndarraywould offer exactly the same tradeoffs as a MATLAB matrix.