Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6956425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:52:05+00:00 2026-05-27T14:52:05+00:00

May I know why ndarray allows floating point index accessing, and what does that

  • 0

May I know why ndarray allows floating point index accessing, and what does that mean?

>>> wk1 = numpy.arange(10)
>>> wk1[1:2.8]
array([1])
>>> wk1 = [1,2,3,4,5,6,7,8,9,10]
>>> wk1[1:2.8]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method
>>>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:52:05+00:00Added an answer on May 27, 2026 at 2:52 pm

    This can be useful, and I wonder why other classes don’t do it the way numpy does.

    One particularly helpful time when I’ve noticed this is if your numpy array is an image, and you have an event handler for mouse clicks which give you event.xdata and event.ydata as floats, then you can still get a region of interest using the slices without having to convert them to pixel coordinates. For example, suppose you were cropping an image or zooming in an image by clicking and dragging a selection – the mouse position in the image will generally be on sub-pixel coordinates except for the special case where the image is displayed 1:1 scale.

    As a side note, non-integer slice notation (even complex numbers in slices) can be used in their index tricks classes r_ and c_, for example:

    >>>np.r_[0:3:0.1]
    array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ,
            1.1,  1.2,  1.3,  1.4,  1.5,  1.6,  1.7,  1.8,  1.9,  2. ,  2.1,
            2.2,  2.3,  2.4,  2.5,  2.6,  2.7,  2.8,  2.9])
    
    >>>np.c_[-1:1:9j]
    array([[-1.  ],
           [-0.75],
           [-0.5 ],
           [-0.25],
           [ 0.  ],
           [ 0.25],
           [ 0.5 ],
           [ 0.75],
           [ 1.  ]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As you may know, elements that contain floating elements won't stretch around their child
As some of you may know, use of the LIMIT keyword in MySQL does
Long version: Those familiar to the standardization nightmare of the RSS-family, may know that
We all may know the following snippet that gets the first entry of the
Good afternoon everyone! As you may know, many companies that sell SSL certificates offer
You may know the Windows compliance tool that helps people to know if their
Some may know that PHP methods can be remotely invoked from Flash. Sometimes the
You awesome people may know how to do this. I know that once I
Those who know C++ may know what I mean by 'unity build': *.cpp files
Many of you may know the classic windows screen saver . Does anyone have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.