size

vector-遍历

匿名 (未验证) 提交于 2019-12-02 23:49:02
一个 vector “知道”它的大小,所以可以如下打印一个 vector 的所有元素: vector<int>v = {5,7,9,4,6,8}; for(int i = 0;i < v.size();++i) { cout<<v[i]<<'\'<<endl; } 函数调用 v.size()返回 vector v 的元素个数。v.size()能让我们能访问到 vector 的元素,而不会意外越界。 v的第一个元素是v[0],最后一个元素是v[v.size()-1]。若v.size()==0,则v没有元素,为空。 一个简洁的遍历序列元素的方法: 例如: vector<int>v = {5,7,9,4,6,8}; for(int x : v) //对每个vectorv的元素X cout<<x<<'\n\<<endl; 这被称为是“范围for循环”,这里的”范围“是指”元素序列“。可将for(int x:v)理解为”对每个 v 的整型元素 x"该循环的含义等价于[0:v.size())进行循环。 “范围for循环”常用于遍历序列的所有元素且每次只访问一个元素的情形。 这个“范围for循环”我个人的顾虑,会不会跟for循环搞混呐,没操作过,真没谱呐。

numpy之随机数模块---random模块

匿名 (未验证) 提交于 2019-12-02 23:47:01
一、二项分布 ''' 随机数:模块为random模块---生成服从特定统计规律的随机数序列 1.二项分布(binomial):就是重复n次的伯努利实验,每次实验只有两种可能的结果,而且两种结果发生与否相互独立。 事件发生与否的概率在每次实验中都是保持不变的 ----numpy中实现:np.random.binomial(n,p,size)-->产生size个随机数,符合二项分布, 每个随机数来自n次尝试中成功的次数,其中每次尝试成功的概率为p ''' import numpy as np r = np.random.binomial(10, 0.8, 1) print(r) # 求:命中率0.8时,投10球进8球的概率、 # 投100000轮看看有多少轮进了10个球 r = np.random.binomial(10, 0.8, 100000) print(r[r == 8].size / r.size) print((r == 0).sum()/r.size) print((r == 1).sum()/r.size) print((r == 2).sum()/r.size) print((r == 3).sum()/r.size) print((r == 4).sum()/r.size) print((r == 5).sum()/r.size) print((r == 6)

Elasticsearch聚合 之 Terms

匿名 (未验证) 提交于 2019-12-02 23:43:01
2019独角兽企业重金招聘Python工程师标准>>> 之前总结过metric聚合的内容,本篇来说一下bucket聚合的知识。Bucket可以理解为一个桶,他会遍历文档中的内容,凡是符合要求的就放入按照要求创建的桶中。 本篇着重讲解的terms聚合,它是按照某个字段中的值来分类: 比如性别有男、女,就会创建两个桶,分别存放男女的信息。默认会搜集doc_count的信息,即记录有多少男生,有多少女生,然后返回给客户端,这样就完成了一个terms得统计。 Terms聚合 { "aggs" : { "genders" : { "terms" : { "field" : "gender" } } } } 得到的结果如下: { ... "aggregations" : { "genders" : { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets" : [ { "key" : "male", "doc_count" : 10 }, { "key" : "female", "doc_count" : 10 }, ] } } } 数据的不确定性 使用terms聚合,结果可能带有一定的偏差与错误性。 举个例子: 我们想要获取name字段中出现频率最高的前5个。 此时,客户端向ES发送聚合请求

Opencv Linemod 匹配部分源码解析

匿名 (未验证) 提交于 2019-12-02 23:34:01
函数接口: void Detector::match(const std::vector<Mat>& sources, float threshold, std::vector<Match>& matches, sources为输入图像,threshold是用户数值0-100之间,matches匹配数据,class_ids定义模板名,quantized_images(ResponseMap),mask掩膜 根据定义特征计算线性存储的ResponseMap // For each pyramid level, precompute linear memories for each modality std::vector<Size> sizes; for (int l = 0; l < pyramid_levels; ++l) { int T = T_at_level[l]; std::vector<LinearMemories>& lm_level = lm_pyramid[l]; if (l > 0) { for (int i = 0; i < (int)quantizers.size(); ++i) quantizers[i]->pyrDown(); } Mat quantized, spread_quantized; std::vector<Mat> response

Valgrind检测内存读写越界

匿名 (未验证) 提交于 2019-12-02 23:34:01
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengqiuming/article/details/90311919 内存读写越界是指访问了没有权限访问的内存地址空间,比如访问数组时越界,对动态内存访问超出了申请时内存的大小范围。 #include<stdlib.h> #include<iostream> using namespace std; int main(){ int len=4; int *pt=(int *)malloc(len*sizeof(int)); int *p=pt; for(int i=0;i<len;i++) p++; *p=5; cout<<"the value of p is "<<*p<<endl; return 0; } [root@localhost charpter05]# g++ -g 0511.cpp -o 0511 [root@localhost charpter05]# ./0511 the value of p is 5 [root@localhost charpter05]# valgrind ./0511 ==18335== Memcheck, a memory error detector ==18335== Copyright (C) 2002-2017, and

Python中的size、shape、len和count

匿名 (未验证) 提交于 2019-12-02 22:54:36
*人生苦短,我用python~* len():返回对象的长度,注意不是length()函数 len([1,2,3]),返回值为3 len([[1,2,3],[3,4,5]]),返回值为2 count():计算包含对象个数 [1,1,1,2].count(1),返回值为3 ‘asddf’.count(‘d’),返回值为2 size()和shape () 是numpy模块中才有的函数 size():计算数组和矩阵所有数据的个数 a = np.array([[1,2,3],[4,5,6]]) np.size(a),返回值为 6 np.size(a,1),返回值为 3 shape ():得到矩阵每维的大小 np. shape (a),返回值为 (2,3) 另外要注意的是,shape和size既可以作为函数,也可以作为ndarray的属性 a.size,返回值为 6, a.shape,返回值为 (2,3) 文章来源: Python中的size、shape、len和count

Python的PIL库中的thumbnail方法

匿名 (未验证) 提交于 2019-12-02 22:51:30
代码: from PIL import Image img = Image.open('D:\\image_for_test\\Spee.jpg') print("初始尺寸",img.size) img.thumbnail((128,128)) print("默认缩放NEARESET",img.size) img.thumbnail((127,127),Image.BILINEAR) print("BILINEAR",img.size) img.thumbnail((126,126),Image.BICUBIC) print("BICUBIC",img.size) img.thumbnail((125,125),Image.ANTIALIAS) print("ANTIALIAS",img.size) 结果: 文章来源: Python的PIL库中的thumbnail方法

Python 数据分析:让你像写 Sql 语句一样,使用 Pandas 做数据分析

匿名 (未验证) 提交于 2019-12-02 22:51:30
import pandas as pd import numpy as np url = ('https://raw.github.com/pandas-dev/pandas/master/pandas/tests/data/tips.csv') tips = pd.read_csv(url) output = tips.head() Output: total_bill tip sex smoker day time size 0 16.99 1.01 Female No Sun Dinner 2 1 10.34 1.66 Male No Sun Dinner 3 2 21.01 3.50 Male No Sun Dinner 3 3 23.68 3.31 Male No Sun Dinner 2 4 24.59 3.61 Female No Sun Dinner 4 sql 语句: SELECT total_bill, tip, smoker, time FROM tips LIMIT 5; 。 output = tips[['total_bill', 'tip', 'smoker', 'time']].head(5) Output: total_bill tip smoker time 0 16.99 1.01 No Dinner 1 10.34 1.66 No Dinner

How can I get the size of an std::vector as an int?

邮差的信 提交于 2019-12-02 21:51:52
I tried: #include <vector> int main () { std::vector<int> v; int size = v.size; } but got the error: cannot convert 'std::vector<int>::size' from type 'std::vector<int>::size_type (std::vector<int>::)() const noexcept' {aka 'long unsigned int (std::vector<int>::)() const noexcept'} to type 'int' Casting the expression to int like this: #include <vector> int main () { std::vector<int> v; int size = (int)v.size; } also yields an error: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>;