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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:32:54+00:00 2026-06-07T22:32:54+00:00

For a minimal working example, let’s digitize a 2D array. numpy.digitize requires a 1D

  • 0

For a minimal working example, let’s digitize a 2D array. numpy.digitize requires a 1D array:

import numpy as np
N = 200
A = np.random.random((N, N))
X = np.linspace(0, 1, 20)
print np.digitize(A.ravel(), X).reshape((N, N))

Now the documentation says:

… A copy is made only if needed.

How do I know if the ravel copy it is “needed” in this case? In general – is there a way I can determine if a particular operation creates a copy or a view?

  • 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-07T22:32:56+00:00Added an answer on June 7, 2026 at 10:32 pm

    This question is very similar to a question that I asked a while back:

    You can check the base attribute.

    a = np.arange(50)
    b = a.reshape((5, 10))
    print (b.base is a)
    

    However, that’s not perfect. You can also check to see if they share memory using np.may_share_memory.

    print (np.may_share_memory(a, b))
    

    There’s also the flags attribute that you can check:

    print (b.flags['OWNDATA'])  #False -- apparently this is a view
    e = np.ravel(b[:, 2])
    print (e.flags['OWNDATA'])  #True -- Apparently this is a new numpy object.
    

    But this last one seems a little fishy to me, although I can’t quite put my finger on why…

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

Sidebar

Related Questions

Somehow, I can't seem to correctly implement a SortedMap. Here's a minimal (non-)working example:
Could someone please show me a minimal working example of using C language for
I am using mingw g++ 4.6.1 with -O0, WinXP SP2. Minimal working example is
I'm working on a minimal Firefox extension that loads a web page into an
I'm working on building a very minimal nfs root for a Xen Dom0 host,
I am working on a query, and have found minimal documentation from Microsoft on
Anyone have an minimal example of ASP.NET MVC and dotnetcharting.com control lying around? Thanks,
Currently I am working on a bit of code which (I believe) requires quite
How can I deliver a module that requires patching flymake, with minimal startup time
I found in a related question a minimal example to send a message via

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.