Hi all
I have a large vector with float point numbers in it, for example
(1.1, 2.1 , 3.2 , 3.3 , 4, 6, 3.2, 8). Is there an easy way to
determine
how many uique elements in the array?
Thanks
Rick 3 1789 go***********@g mail.com wrote: I have a large vector with float point numbers in it, for example (1.1, 2.1 , 3.2 , 3.3 , 4, 6, 3.2, 8). Is there an easy way to determine how many uique elements in the array?
1. copy vector(*)
2. std::sort()
3. std::unique
(*) you must copy the vector because std::unique deletes/overwrites
elements. go***********@g mail.com wrote: I have a large vector with float point numbers in it, for example (1.1, 2.1 , 3.2 , 3.3 , 4, 6, 3.2, 8). Is there an easy way to determine how many uique elements in the array?
Have you looked at 'std::unique'? It's mutating, so you might want
to make a copy of your array (unless you don't care that it's going
to re-sort them).
V
Rapscallion wrote: go***********@g mail.com wrote: I have a large vector with float point numbers in it, for example (1.1, 2.1 , 3.2 , 3.3 , 4, 6, 3.2, 8). Is there an easy way to determine how many uique elements in the array?
1. copy vector(*) 2. std::sort() 3. std::unique
You can also use a set:
#include <set>
#include <iterator>
template <class F>
typename std::iterator_t raits<F>::diffe rence_type
count_unique( F first, F last )
{
typedef typename std::iterator_t raits<F>::value _type V;
return std::set<V>( first, last ).size();
};
// ...
std::cout << count_unique( v.begin(), v.end() ) << "\n"; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: kevin parks |
last post by:
hi. I've been banging my head against this one a while and have asked
around, and i
am throwing this one out there in the hopes that some one can shed
some light on
what has turned out to be a tough problem for me (though i am getting
closer).
i have been mucking with a lot of data in a dictionary that looks
like:
|
by: les_ander |
last post by:
Hi,
I have many set objects some of which can contain same group of object
while others can be subset of the other. Given a list of sets,
I need to get a list of unique sets such that non of the set is an
subset of another or contain exactly the same members.
Tried to do the following:
s1=set()
s2=set()
s3=set()
|
by: superprad |
last post by:
Is there an easy way to grab the Unique elements from a list?
For Example:
data =
what I am looking for is the unique elements 0.4 and 0.9 with their
index from the list.
Probably something like a Hash Table approach!!
I would like to get this done without unnecessary overhead.And the list
could be essentially anything strings,floats,int etc...
|
by: Victor Engmark |
last post by:
When looking for a method to fetch unique elements and counting the
number of occurences of each of them, I found quite a lot of gross
examples of complex XSL. But after realizing the subtle difference
between "." and "current()", I found a neat way of doing the same
without keys or generate-id():
<xsl:template match="/">
<!-- Selects all "new" elements -->
<xsl:for-each select="//Name">
<!-- Display the element -->
|
by: Rolf Kemper |
last post by:
Dear Experts,
I got stuck with the following problem and need your help.
What I wnat to do is to get a set of distinct nodes.
Before the distinct I have selected the multiple occourences already
sucsessfully. However , the rest does not work as expected.
Hope someone can help on that.
Rolf
| |
by: Rich S. |
last post by:
Hi
In an earlier posting I was asking how to read thru millions of data records
keeping the top 2000 (where the top values are based upon a field in the
record) and niklasb suggested using a priority_queue like so
------------------- start old message ---------------------
A more efficient way than what you describe would be
to use priority_queue. Define the predicate in such
|
by: smachin1000 |
last post by:
Hi All,
In the sample schema & document below, I'd like the attribute "name" to
be unique for all function elements under function_list. The tools I'm
using (XML Spy and xmllint) all validate the sample document and do not
pick up that the name is not unique.
Any clues as to what could be going wrong?
Thanks.
|
by: Miguel Isidoro |
last post by:
Hi all,
I am trying to include a xsd:unique element in my schema to make an
attribute of an element unique at the whole document level.
Consider the following xml fragment:
<Form>
<Question>
<Response id="response1">
|
by: daldridge |
last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't
yet been able to get appropriate template/select/for-each processing
working. I don't fully grok the Muenchian technique yet (still an XSLT
n00b), but I'm not sure that's the way to go anyway...
What I'm trying to accomplish is generation of XML Schema output from a
given XML input, with "xs:import" elements in the output with the
"namespace" and "schemaLocation"...
|
by: tthunder |
last post by:
Hi @all,
Please check the following XML file and XML schema definition below
first:
-------
XML File (full):
-------
<?xml version="1.0" encoding="UTF-8"?>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |