using Numeric in C++

Discussion in 'C++' started by GujuBoy, Jun 2, 2005.

  1. GujuBoy

    GujuBoy Guest

    I have made a program in "Python" which imports Numeric and calls the
    function

    ones_array = Numeric.ones(blah,blah)

    i see that C++ has a <numeric> library and i was wondering where the
    "ones" function is ... in that library...

    please help
     
    GujuBoy, Jun 2, 2005
    #1
    1. Advertising

  2. GujuBoy

    John Carson Guest

    "GujuBoy" <> wrote in message
    news:
    > I have made a program in "Python" which imports Numeric and calls the
    > function
    >
    > ones_array = Numeric.ones(blah,blah)
    >
    > i see that C++ has a <numeric> library and i was wondering where the
    > "ones" function is ... in that library...



    Since this is not a Python group, perhaps you would like to tell us what the
    "ones" function does. I would not assume that the common use of the word
    "numeric" implies common functionality between Python and the C++ library.

    --
    John Carson
     
    John Carson, Jun 2, 2005
    #2
    1. Advertising

  3. GujuBoy

    Guest

    The 'ones'-function in Numeric creates a new array of a given
    size/dimension and fills it with the value '1'.

    A simple C++ version of this code could be the following:

    #import <cstring>

    double [] ones_array = new double[blah] // initialize an array with
    'blah' length
    memset(ones_array, 1, sizeof(double))

    If you want a more advanced array class, you might want to take a look
    at the STL vector-class.

    --
    Reidar
     
    , Jun 2, 2005
    #3
  4. * :
    > [mostly incoherent]


    > The 'ones'-function in Numeric creates a new array of a given
    > size/dimension and fills it with the value '1'.


    There is no 'ones' function and there is no Numeric in standard C++.


    > A simple C++ version of this code could be the following:
    >
    > #import <cstring>


    This is not standard C++.


    > double [] ones_array = new double[blah] // initialize an array with


    This is not standard C++.


    > memset(ones_array, 1, sizeof(double))


    This is Undefined Behavior.


    > If you want a more advanced array class, you might want to take a look
    > at the STL vector-class.


    That's good advice.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jun 2, 2005
    #4
  5. GujuBoy

    Pete Becker Guest

    wrote:

    > The 'ones'-function in Numeric creates a new array of a given
    > size/dimension and fills it with the value '1'.
    >
    > A simple C++ version of this code could be the following:
    >
    > #import <cstring>
    >
    > double [] ones_array = new double[blah] // initialize an array with
    > 'blah' length
    > memset(ones_array, 1, sizeof(double))
    >


    double *ones_array = new double[blah];
    fill(ones_array, ones_array + blah, 1.0);
    or:
    fill_n(ones_array, blah, 1.0);

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
     
    Pete Becker, Jun 2, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chad
    Replies:
    2
    Views:
    5,775
    Chad Dokmanovich
    Dec 28, 2005
  2. Phil
    Replies:
    0
    Views:
    305
  3. Replies:
    5
    Views:
    946
    X-Centric
    Jun 30, 2005
  4. darrel
    Replies:
    4
    Views:
    827
    darrel
    Jul 19, 2007
  5. jobs

    int to numeric numeric(18,2) ?

    jobs, Jul 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    971
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 22, 2007
Loading...

Share This Page