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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:08:00+00:00 2026-05-27T02:08:00+00:00

I have a 1D numpy array containing complex numbers (eg. numpy.complex64). I need to

  • 0

I have a 1D numpy array containing complex numbers (eg. numpy.complex64). I need to create views on this array, but I don’t know how to create a view given a list or range of indices to include in the view.

>>> myArray = np.ndarray(shape=(1000,), dtype=np.complex64)

I know how to create a view on consecutive items, for example the first 100 elements:

>>> myView = myArray[:100]

As I experimented, it’s not possible to create a view on a singular item, like myArray[2] because if I modified that value, it wouldn’t change the underlying array. This is OK, but I hope there is a way to construct a view from multiple arbitrary indices, so a function like this would be great:

>>> myView = createView(myArray, indices=(0, 1, 6, 7, 13))

which would return a view that points to those indices given in a list (or any iterable form), and if I change myView, it would change myArray like it should.

Is this possible, or is there a sane workaround?
Thanks

edit:

To explain why I need this: I want to copy the array to OpenCL device memory (and back). I need a different order of the elements on the device than in the original array, and these shorter arrays would be treated as vectors, and matrix multiplication will take place in the OpenCL kernel. If the elements are not copied to the device memory in the order that is required, memory coalescing wouldn’t be possible, and significant performance decrease would occur, not to mention the additional logic that would be needed on OpenCL side.

In my case, it is possible to do this with evenly spaced views, but I wonder if there’s a more general way. A small CPU-side performance decrease is OK if a more general implementation can be done.

  • 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-27T02:08:01+00:00Added an answer on May 27, 2026 at 2:08 am

    As far as I know, you can’t have a view on arbitrary indices; only on consecutive indices or regularly spaced indices. This is because the elements in the view’s underlying memory store have to be separated by a constant number of bytes, otherwise all the fast NumPy routines don’t work.

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

Sidebar

Related Questions

I have a 2D numpy array. Is there a way to create a view
I have a numpy array containing: [1, 2, 3] I want to create an
I have a problem with some numpy stuff. I need a numpy array to
I have a very large numpy array (containing up to a million elements) like
This is a simplification of my question. I have a numpy array: x =
I have a 48x365 element numpy array where each element is a list containing
I have a 2D numpy array. Some of the values in this array are
I have this numpy array: a = np.array([[[1,2,3],[-1,-2,-3]],[[4,5,6],[-4,-5,-6]]]) b is a transpose of a
Say I have an array in NumPy containing evaluations of a continuous differentiable function,
I have a NumPy array [1,2,3,4,5,6,7,8,9,10,11,12,13,14] and want to have an array structured like

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.