Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Multiply a scalar to every element of a vector
Multiply a scalar to every element of a vector [message #56481] Wed, 17 March 2021 08:08 Go to previous message
sinpeople is currently offline  sinpeople
Messages: 29
Registered: October 2020
Location: Singapore
Promising Member

Hi folks,

What's the most elegant way to multiply every element of a vector to a scalar? "u=s*v", in which v is the vector, s is a scalar, u is the vector of the same size of v.
The simplest way to do it is to use a for loop. In the STL, there is a transform function. But I have no idea how to adapt it to this case.

Thank you!

Best Regards
David
 
Read Message
Read Message
Previous Topic: deprecated function encountered
Next Topic: Pass data of Vector<Vector<double>> into a function call
Goto Forum:
  


Current Time: Tue Jun 04 09:58:52 CEST 2024

Total time taken to generate the page: 0.02366 seconds