Typeerror:only integer scalar arrays can be converted to a scalar index

Source: Internet
Author: User
Tags scalar

Problem Description : An error occurred while accessing the elements in the list: typeerror:only integer scalar arrays can is converted to a scalar index

1 Voteilabel = labels[sorteddistindicies[i]]

Suppose A is a list, and if you visit A[object] The above error, you can refer to the following content

Reason Description : This is typically because the object in A[object] is an integer, and the object you provide to the list is not an integer, so you cannot access the list element as an index to the list

recommendation : Use the statement print (type object) to see if the object you provided is an integer, and if not, just provide the integer as needed

For example, sorteddistindicies[i in the above code], I thought it was an integer, and the result is an array, so the compiler means that only a scalar integer can be used as a scalar index, and then I change the code to Sorteddistindicies[0][i] After getting an integer, by compiling the

Typeerror:only integer scalar arrays can be converted to a scalar index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.