+2 votes
in Programming Languages by (7k 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

0 votes
by (13.5k points)

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])

...