Connecting Tech Pros Worldwide Help | Site Map

using Numeric in C++

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 04:58 AM
GujuBoy
Guest
 
Posts: n/a
Default using Numeric in C++

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


  #2  
Old July 23rd, 2005, 04:58 AM
John Carson
Guest
 
Posts: n/a
Default 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

  #3  
Old July 23rd, 2005, 04:59 AM
reidarok@gmail.com
Guest
 
Posts: n/a
Default 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

  #4  
Old July 23rd, 2005, 04:59 AM
Alf P. Steinbach
Guest
 
Posts: n/a
Default 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?
  #5  
Old July 23rd, 2005, 04:59 AM
Pete Becker
Guest
 
Posts: n/a
Default 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)
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.