TypeError: concatenate() got an unexpected keyword argument 'dtype'

Viewed 1743

I can clearly see an argument named dtype in numpy documentation.

What I can't do, is this:

np.concatenate((np.array([]),np.array([3,4])),dtype=np.int64)

Which gives this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 4, in concatenate
TypeError: concatenate() got an unexpected keyword argument 'dtype'

Without the dtype argument I get this array:

>>> np.concatenate((np.array([]),np.array([3,4])))
array([3., 4.])

But I don't want those to be decimal points (float) values.

Why can't I use the dtype argument? How to make it int on concatenation even if my initial arrays had let's say float values?

2 Answers

If you look at the documentation of version 1.19, dtype was not an argument of concatenate. So dtype was introduced in version 1.20.

Then you can update your numpy version. Otherwise, if your first array is of type np.int64 and the second one contains only int, the resulting type is np.int64.

np.concatenate((np.array([], dtype=np.int64), np.array([3, 4])))

array([3, 4])
Related