You need to put the arrays you want to combine into a sequence (usually a tuple or list) in the argument.
tmp = np.concatenate((allValues, np.array([30], float))) tmp = np.concatenate([allValues, np.array([30], float)])
np.concatenate documentation for np.concatenate . Note that the first argument is the sequence (e.g. list, tuple) of the arrays. This does not take them as separate arguments.
As far as I know, this API is shared by all numpy concatenation functions: concatenate , hstack , vstack , dstack and column_stack all take one main argument, which should be some sequence of arrays.
The reason you get this particular error is because arrays are also sequences. But that means concatenate interprets allValues as a sequence of arrays for concatenation. However, each allValues element is a float, not an array, and therefore is interpreted as a zero-dimensional array. As stated in the error, these "arrays" cannot be combined.
The second argument is taken as the second (optional) argument to concatenate , which is the axis to concatenate. This only works because the second argument has one element that can be distinguished as a whole and therefore is a valid value. If you put an array with a large number of elements in the second argument, you would get another error:
a = np.array([1, 2]) b = np.array([3, 4]) np.concatenate(a, b) # TypeError: only length-1 arrays can be converted to Python scalars
Roger fan
source share