Concatenating empty array in Numpy

if you know the number of columns before hand: >>> xs = np.array([[1,2,3,4,5],[10,20,30,40,50]]) >>> ys = np.array([], dtype=np.int64).reshape(0,5) >>> ys array([], shape=(0, 5), dtype=int64) >>> np.vstack([ys, xs]) array([[ 1., 2., 3., 4., 5.], [ 10., 20., 30., 40., 50.]]) if not: >>> ys = np.array([]) >>> ys = np.vstack([ys, xs]) if ys.size else xs array([[ … Read more

Why is 24.0000 not equal to 24.0000 in MATLAB?

The problem you’re having relates to how floating-point numbers are represented on a computer. A more detailed discussion of floating-point representations appears towards the end of my answer (The “Floating-point representation” section). The TL;DR version: because computers have finite amounts of memory, numbers can only be represented with finite precision. Thus, the accuracy of floating-point … Read more

How to deal with name/value pairs of function arguments in MATLAB

I prefer using structures for my options. This gives you an easy way to store the options and an easy way to define them. Also, the whole thing becomes rather compact. function example(varargin) %# define defaults at the beginning of the code so that you do not need to %# scroll way down in case … Read more

In MATLAB, are variables REALLY double-precision by default?

They’re doubles. vpa() is simply choosing to display non-significant digits beyond the floating point relative accuracy, where printf() and disp() truncate or zero them out. You’re only getting your original four digits back out because the literal you chose to initialize num with just happens to be the exact decimal expansion of a binary double … Read more