+2 votes
in Programming Languages by (73.2k points)

I am concatenating two one dimensional numpy arrays, but I am getting the error: "TypeError: only integer scalar arrays can be converted to a scalar index". What is wrong in the code?

>>> import numpy

>>> a = numpy.array([1, 2, 3])

>>> b = numpy.array([5, 6])

>>> numpy.concatenate(a, b)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: only integer scalar arrays can be converted to a scalar index

1 Answer

+2 votes
by (346k points)
selected by
 
Best answer

You are missing [] in concatenate(). See the modified code.

>>> import numpy
>>> a = numpy.array([1, 2, 3])
>>> b = numpy.array([5, 6])
>>> numpy.concatenate([a, b])
array([1, 2, 3, 5, 6])


...