using Numeric in C++

G

GujuBoy

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
 
J

John Carson

GujuBoy said:
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.
 
R

reidarok

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.
 
A

Alf P. Steinbach

* (e-mail address removed):
[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.
 
P

Pete Becker

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);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top