This content originally appeared on CodeSource.io and was authored by Deven
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']
The post Solved – only integer scalar arrays can be converted to a scalar index appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-03-09T16:53:10+00:00) Solved – only integer scalar arrays can be converted to a scalar index. Retrieved from https://www.scien.cx/2021/03/09/solved-only-integer-scalar-arrays-can-be-converted-to-a-scalar-index/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.