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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:57:28+00:00 2026-06-11T11:57:28+00:00

I am trying to wrap my head around the numpy implementation of PEP3118. How

  • 0

I am trying to wrap my head around the numpy implementation of PEP3118. How exactly does buffer access work in numpy.

>>> p = numpy.getbuffer(numpy.arange(10))
>>> p
<read-write buffer for 0x1003e5b10, size -1, offset 0 at 0x1016ab4b0>
>>> numpy.frombuffer(p)
array([  0.00000000e+000,   4.94065646e-324,   9.88131292e-324,
     1.48219694e-323,   1.97626258e-323,   2.47032823e-323,
     2.96439388e-323,   3.45845952e-323,   3.95252517e-323,
     4.44659081e-323])

So I am getting unexpected returns. I would expect to see an array with 10 elements from 0-9. I can get into the array and read/write though.

>>> j = numpy.frombuffer(p)
>>> j
array([  0.00000000e+000,   4.94065646e-324,   9.88131292e-324,
     1.48219694e-323,   1.97626258e-323,   2.47032823e-323,
     2.96439388e-323,   3.45845952e-323,   3.95252517e-323,
     4.44659081e-323])
>>> j += 1
>>> j
array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])

So it looks like the buffer is initializing to all zeros, which I can then write to. The functionality that I am expecting is to be able to build the array (with arange or asarray) directly to the buffer with getbuffer. Is that not possible?

  • 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-11T11:57:29+00:00Added an answer on June 11, 2026 at 11:57 am

    You have a simple dtype problem. The buffer you create with

    np.getbuffer(np.arange(10))
    

    has a dtype=int, because np.arange uses dtype=int by default.

    Then, when you try to read your buffer with

    np.frombuffer(p)
    

    you’re in fact using the dtype=float default of np.frombuffer. Instead, use

    np.frombuffer(p, dtype=int)
    

    et voilà, you get

    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to wrap my head around how to make asynchronous programming work.
Trying to wrap my head around JTA and have arbitrarily chosen Bitronix as the
Trying to wrap my head around the jQuery .not() function, and running into a
Im trying to wrap my head around MVVM. I understand a lot of it,
I'm trying to wrap my head around Arquillian and am just not fundamentally understanding
I am trying to wrap my head around serialization. But what happens if for
I am trying to wrap my head around Apache Camel, which appears to be
I am trying to wrap my head around javascript modules, but I'm unsure how
I'm trying to wrap my head around this and I think the easiest way
I'm trying to wrap my head around Object Oriented programming. But I'm having some

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.