question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent behavior if fill data outside of array boundaries

See original GitHub issue

Sorry, if it is duplicate, but I didn’t succeed to formulate search query properly.

When inserting data out of array boundaries, sometimes numpy don’t throw an error

Reproducing code example:

import numpy as np
a =  np.array([1,2,3])
a[10:12] = [10, 10]   # raises a ValueError
a[10:11] = [10]   # does nothing, no exception, just silently passes

I expect both lines behave consistently, f.ex. throw the same ValueError exception

Numpy/Python version information:

numpy 1.18.1 Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
eric-wiesercommented, Feb 3, 2020

You’re right, that page could do with an example with a length-0 dimension.

The key to understanding is that when “expanding” from 1 to N, 0 is a legal value for N just like any other value.

1reaction
eric-wiesercommented, Mar 20, 2020

Doesn’t my comment above cover that? In a situation where the code is “broadcast this value to all elements satisfying this condition”, you want the broadcast to succeed even if sometimes no elements satisfy the condition

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it dangerous merely to read outside an array in C [duplicate]
I have commands and data in a randomly generated array, but sometimes the commands require uncertain amounts of data. Do I need to...
Read more >
Index outside bounds of array error - Office - Microsoft Learn
"Index was outside the bounds of the array" error when you import data from multiple tables in a SQL Server database to an...
Read more >
CWE-125: Out-of-bounds Read (4.9) - MITRE
A crash can occur when the code reads a variable amount of data and assumes that a sentinel exists to stop the read...
Read more >
Inconsistent error reporting for out of range indexing ... - GitHub
I 'm observing inconsistent error behavior with parallel and serial out-of-range indexing dependent on whether operating on reflected list vs ...
Read more >
The logical indices in position 1 contain a true value outside of ...
I cannot emphasize enough how important it is to put up a complete set of data/code that people can run and duplicate the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found