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

  • Home
  • SEARCH
  • 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 7733933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:07:24+00:00 2026-06-01T07:07:24+00:00

A toy-case for my problem: I have a numpy array of size, say, 1000:

  • 0

A toy-case for my problem:

I have a numpy array of size, say, 1000:

import numpy as np
a = np.arange(1000)

I also have a “projection array” p which is a mapping from a to another array b:

p = np.random.randint(0,1000,(1000,1000))

It is easy to get b from a using “fancy indexing”:

b = a[p]

But b is not a view, as noted by several previous questions/answers and the numpy documentation.

Unfortunately, in my case only the values in a change over the course of a long simulation and using fancy indexing at each iteration to obtain b becomes very costly. I only read from b and do not modify it.

I understand it is not possible (yet) to solve this with fancy indexing.

I was wondering if anyone had a similar problem/bottleneck and came up with some other workaround?

  • 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-01T07:07:25+00:00Added an answer on June 1, 2026 at 7:07 am

    What your asking for isn’t practical and that’s why the numpy folks haven’t implemented it. You could do it yourself with something like:

    class FancyView(object):
        def __init__(self, array, index):
            self._array = array
            self._index = index.copy()
        def __array__(self):
            return self._array[self._index]
        def __getitem__(self, index):
            return self._array[self._index[index]]
    
    b = FancyView(a, p)
    

    But notice that the expensive a[p] operation will get called every time you use b as an array. There is no other practice way of making a ‘view’ of this kind. Numpy can get away with using views for basic slicing because it can manipulate the strides, but there is no way to do something like this using strides.

    If you only need parts of b you might be able to get some time savings by indexing the fancy view instead of using it as an array.

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

Sidebar

Related Questions

Here's my toy setup. I have 3 tables. One table is a guest list
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have been developing a toy editor, and I want my editor to look
Imagine I have a stack-based toy language that comes with the operations Push, Pop,
According to the following description I have to frame a CASE...END statement in SQL
I have following two arrays and the code to find array_diff: $obs_ws = array(you,
I have such case classes: abstract class Tree case class Sum(l: Tree, r: Tree)
I have a server which takes some messages x and outputs some messages Y.
This is toy-example.hs: {-# LANGUAGE ImpredicativeTypes #-} import Control.Arrow data From = From (forall
This is just a toy grammar to test backtracking: from pyparsing import * a

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.