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 9325357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:48:52+00:00 2026-06-19T04:48:52+00:00

I created a numpy.ndarray with value import numpy as np from numpy import nonzero

  • 0

I created a numpy.ndarray with value

import numpy as np
from numpy import nonzero

data = np.zeros((5, 5))
data
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

i wish to change some values with 1

data[0,0] = 1
data[4,4] = 1

data
array([[ 1.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  1.]])

if i change 0 with 5 using negative values i have

data[-5,-5] = 5
data[-4,-4] = 5

>>> data
array([[ 5.,  0.,  0.,  0.,  0.],
       [ 0.,  5.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

1- I don’t understand why i have not an error message as

>>> data[10,10] = 5
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
IndexError: index (10) out of range (0<=index<5) in dimension 0

2- it’s not clear why with data[-5,-5] = 5 and data[-4,-4] = 5 the value 5 is inserted in position 0,0 and 1,1

  • 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-06-19T04:48:54+00:00Added an answer on June 19, 2026 at 4:48 am

    From the documentation:

    Negative indices are interpreted as counting from the end of the array

    This is the standard Python indexing behavior (used in Python lists, etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an array thusly: import numpy as np data = np.zeros( (512,512,3),
I created a python .py with some sort methods. I'm using numpy so that
I have to create a 2D numpy array from the values x, y from
I have a 2D numpy array that's created like this: data = np.empty((number_of_elements, 7))
I am new to NumPy and I have created the following array: import numpy
I have an array A on python that has some nan values created by
I've created an array with 3 doubles and one boolen using numpy and written
I'm using numpy to create a cube array with sides of length 100, thus
Created .NET WCF service, tested it - works. Generated schemas from Data and service
I have an object from a library (numpy.ndarray), in which I've substituted the _

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.