Connecting Tech Pros Worldwide Forums | Help | Site Map

using Numeric in C++

GujuBoy
Guest
 
Posts: n/a
#1: Jul 23 '05
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


John Carson
Guest
 
Posts: n/a
#2: Jul 23 '05

re: using Numeric in C++


"GujuBoy" <dirgesh@gmail.com> wrote in message
news:1117687576.491240.277780@g44g2000cwa.googlegr oups.com[color=blue]
> 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...[/color]


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

reidarok@gmail.com
Guest
 
Posts: n/a
#3: Jul 23 '05

re: using Numeric in C++


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

Alf P. Steinbach
Guest
 
Posts: n/a
#4: Jul 23 '05

re: using Numeric in C++


* reidarok@gmail.com:[color=blue]
> [mostly incoherent][/color]
[color=blue]
> The 'ones'-function in Numeric creates a new array of a given
> size/dimension and fills it with the value '1'.[/color]

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

[color=blue]
> A simple C++ version of this code could be the following:
>
> #import <cstring>[/color]

This is not standard C++.

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

This is not standard C++.

[color=blue]
> memset(ones_array, 1, sizeof(double))[/color]

This is Undefined Behavior.

[color=blue]
> If you want a more advanced array class, you might want to take a look
> at the STL vector-class.[/color]

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?
Pete Becker
Guest
 
Posts: n/a
#5: Jul 23 '05

re: using Numeric in C++


reidarok@gmail.com wrote:
[color=blue]
> 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))
>[/color]

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)
Closed Thread