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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:39:20+00:00 2026-05-22T23:39:20+00:00

I am trying to get some data from an module which is a shared

  • 0

I am trying to get some data from an module which is a shared object wrapped with ctypes.
The data is a numeric array so I used numpy array to store the data. But I learned that I
don’t understand how numpy organize the array in memory.

If I had a C function that would fill a array like below:

int filler(int* a,int length){
        int i=0;
        for(i=0;i<length;i++){
                a[i]=i;
        }
        return 0;
}

Then I would call this function in python using ctypes

import ctypes
import numpy
lib = ctypes.cdll.LoadLibrary("libname")    
data = numpy.zeros((1,10),dtype=numpy.int16)
lib.filler(data.ctypes.data,ctypes.c_int(10))
print data

But my output comes out this way.

dtype=numpy.int16
[[0 0 1 0 2 0 3 0 4 0]]

This would make sense if int was 32 bit, but I suppose C int are 16 bits (GCC in openSUSE in a x86 intel machine).
I tried running with dtypes being 32 bits and strangely I get the result I want:

dtype=numpy.int32
[[0 1 2 3 4 5 6 7 8 9]]

Trying to make sense of what is happening I ran with int8 and I got the following:

dtype=numpy.int8
[[0 0 0 0 1 0 0 0 2 0]]

I did give a look give a look at numpy docs, but so far I have not found what the answer.

  • 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-22T23:39:21+00:00Added an answer on May 22, 2026 at 11:39 pm

    This would make sense if int was 32
    bit, but I suppose C int are 16 bits
    (GCC in openSUSE in a x86 intel
    machine). I tried running with dtypes
    being 32 bits and strangely I get the
    result I want:

    Not strange at all: your supposition is wrong, and your machine is 32 bit with a 32 bit int and a 16 bit short int.. unless you’re doing some (rather admirable) retrocomputing!

    Check sizeof(int) and multiply by 8, or simply store numbers in an int and print them out, to convince yourself.

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

Sidebar

Related Questions

I have sugar crm instance and i was trying to get some data from
I am trying to get some form data from POST method. Here's the code
I' trying to get some data from Oracle via ODBC to mySQL database. And
I am trying to get some data from the user and send it to
I'm trying to get some data from a datatable in rich:modal panel The whole
I am trying to get some data from the user and send it to
I'm trying to get some JSON data from a url like this: $url =
I am trying to get some data from a database on the fly and
I am trying to get some data from page to page and then mail
I am trying to get some data from remote server. To achieve this I

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.