error solved

Solved – only integer scalar arrays can be converted to a scalar index


In this article, you will learn how to solve only integer scalar arrays can be converted to a scalar index.

Let’s look at a code example that produces the same error.

import numpy as np

array1 = np.array(['Mango', 'apple', 'Grapes', 'pineapple'])

array2 = np.array(['tomatao', 'potato'])

array3 = np.concatenate(array1, array2)

print(array3)

output

Traceback (most recent call last):
  File "/tmp/sessions/3cabd8e1b9a2abfe/main.py", line 7, in <module>
    array3 = np.concatenate(array1, array2)
TypeError: only integer scalar arrays can be converted to a scalar index

In order to solve this error you require to convert array1 and array2 in to tuple or list like below:

import numpy as np

array1 = np.array(['Mango', 'apple', 'Grapes', 'pineapple'])

array2 = np.array(['tomatao', 'potato'])

array3 = np.concatenate((array1, array2)) # solved by adding it to tuple

print(array3)

output

['Mango' 'apple' 'Grapes' 'pineapple' 'tomatao' 'potato']

Share on social media

//