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…

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Solved – only integer scalar arrays can be converted to a scalar index." Deven | Sciencx - Tuesday March 9, 2021, https://www.scien.cx/2021/03/09/solved-only-integer-scalar-arrays-can-be-converted-to-a-scalar-index/
HARVARD
Deven | Sciencx Tuesday March 9, 2021 » Solved – only integer scalar arrays can be converted to a scalar index., viewed ,<https://www.scien.cx/2021/03/09/solved-only-integer-scalar-arrays-can-be-converted-to-a-scalar-index/>
VANCOUVER
Deven | Sciencx - » Solved – only integer scalar arrays can be converted to a scalar index. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/09/solved-only-integer-scalar-arrays-can-be-converted-to-a-scalar-index/
CHICAGO
" » Solved – only integer scalar arrays can be converted to a scalar index." Deven | Sciencx - Accessed . https://www.scien.cx/2021/03/09/solved-only-integer-scalar-arrays-can-be-converted-to-a-scalar-index/
IEEE
" » Solved – only integer scalar arrays can be converted to a scalar index." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/03/09/solved-only-integer-scalar-arrays-can-be-converted-to-a-scalar-index/. [Accessed: ]
rf:citation
» Solved – only integer scalar arrays can be converted to a scalar index | Deven | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.