当前位置: 首页 > news >正文

动态网站的常用软件开发一个网站需要哪些技术

动态网站的常用软件,开发一个网站需要哪些技术,番禺网站建设怎样,杭州 电子商务网站建设1-lapply()函数介绍: 为什么介绍这个函数呢?因为在windows中使用parLapply()函数和lapply()的结构和用法是非常相似的,我们只需要将原本用lapply(x, fun)迭代函数 直接改写成 parLapply(makeCluster(c1), x, fun)即可,这里的直接…

1-lapply()函数介绍:

为什么介绍这个函数呢?因为在windows中使用parLapply()函数和lapply()的结构和用法是非常相似的,我们只需要将原本用lapply(x, fun)迭代函数 直接改写成 parLapply(makeCluster(c1), x, fun)即可,这里的直接改写是非常简单的,只需要设置使用计算机的核数,后面的参数直接挪到parLapply()中。

lapply() :线性数据迭代

lapply是list(列表)和apply(应用)的组合,函数的作用:对一个列表型或者向量型数据应用一个函数,返回值不区分处理对象,皆是列表结构。这个函数开头的第一个字母“l”表明这个函数的返回类型为列表。

返回值的元素个数与处理对象中的元素个数相同。

该函数的语法结构为:

lapply(X, FUN...)

其中

  1. X代表需要执行运算的列表或者向量;
  2. FUN代表需要运行的函数,这个参数的自定义范围非常广,用户可以将几百行代码封装为要给function(函数)来设置该参数;
  3. 三个点 表示FUN中的相应参数设置。

例子1:

使用均值函数mean来分别计算向量x、y和z的平均值,最后结果会以列表的形式现实在console中。

> x <- 1:10
> y <- 1:10
> z <- 1:10
> lapply(list(x,y,z), mean)
[[1]]
[1] 5.5[[2]]
[1] 5.5[[3]]
[1] 5.5

 例子2:

> x <- c(1:10, NA)
> y <- c(1:10, NA)
> z <- c(1:10, NA)
> lapply(list(x,y,z), function(x) {mean(x, na.rm =T)})
[[1]]
[1] 5.5[[2]]
[1] 5.5[[3]]
[1] 5.5

例子3:

lapply函数等价于for循环,循环4次,每次花费时间5秒钟。总共预期花费时间为20秒=4*5秒

> for(i in 1:4){Sys.sleep(5)}
> lapply(1:4, function(i) Sys.sleep(5))
[[1]]
NULL[[2]]
NULL[[3]]
NULL

2-在Windows使用并行计算,使用parLapply()函数

2.1-并行计算的准备阶段:

只要开始执行并行,需要设置使用计算机的核数,以及关闭执行并行。

流程:设置并行计算的核数-->执行并行计算-->关闭并行计算的集群。

无论使使用哪种并行计算包,都是基于上述三个步骤,1-设置并行计算的核数;2 执行并行计算 3 关闭并行计算的集群。

library(parallel)

#Step1 设置并行计算使用的核数

num_cores <- detectCores(logical=FALSE) #返回的是计算机的物理核数 
cl <- makeCluster(num_cores)# 设置并行计算的核心数,这里num_cores是整数,合理即可
 
# Step2: 执行并行计算的任务
result <- parLapply(cl, x, fun)
 
# Step3: 关闭并行计算的集群
stopCluster(cl)

其中:detectCores()#这个函数中参数logical默认取值为TRUE,该函数返回的是计算机的线程数,如果设置logical=FALSE,返回的是物理核数/CPU。

例如计算机是12核24线程,

  • logical=TRUE,返回的是逻辑核数24线程;
  • logical=FALSE,返回的是物理核数12核。

2.2-parLapply()函数介绍

在Windows 系统中使用parLapply()函数替换lapply函数,进行并行计算,只不过多了一个参数即设置集群makeCluster()。 

也就是说,parLapply( )和lapply( )函数是相似的,在执行并行运算的时候,只需要把之前用lapply()函数写的部分

lappy(x, fun)

改写成 

parLapply(makeCluster(4), x, fun)

其中makeCluster(4) 设置并行计算的核数为4.

2.3-使用parLapply()函数编写执行并行计算

对上面的例子3,在windows系统中使用parLapply()函数执行并行计算:

> system.time(for(i in 1:4){Sys.sleep(5)})用户  系统  流逝 0.00  0.00 20.02> system.time(lapply(1:4,function(i)Sys.sleep(5)))用户  系统  流逝 0.02  0.00 20.02system.time(parLapply(makeCluster(4),1:4, function(i) Sys.sleep(5)))
用户 系统 流逝 
0.04 0.01 5.97 

3-在非Windows中使用mclapply()函数

例如,上面例子3使用mclapply函数执行并行计算

system.time(

mclapply(1:4, function(i) Sys.sleep(5), mc.cores=4) 

)

其中参数mc.cores它告诉mclapply()函数自动将独立计算拆分为多少个进程。

参考:

《R数据科学实践:工具详解与案例分析》(2019年6月出版,机工社)

《R的极客理想:量化投资篇》(2018年1月出版,机工社)

《R: Predictive Analysis》(2017年3月出版 中国图书进出口) (介绍了parLapply函数执行并行计算)

并行运算 R - 搜索结果 - 知乎 (zhihu.com)

【多核的春天】R语言里的并行计算 - 知乎 (zhihu.com) (介绍使用foreach函数执行并行计算)

R语言的并行计算 - 知乎 (zhihu.com) 


文章转载自:
http://scrapbook.xtqr.cn
http://pozsony.xtqr.cn
http://colaholic.xtqr.cn
http://deodorizer.xtqr.cn
http://recvee.xtqr.cn
http://bighead.xtqr.cn
http://kirundi.xtqr.cn
http://misdo.xtqr.cn
http://biennially.xtqr.cn
http://seneca.xtqr.cn
http://misology.xtqr.cn
http://ballast.xtqr.cn
http://steroid.xtqr.cn
http://courge.xtqr.cn
http://coryphee.xtqr.cn
http://endoerythrocytic.xtqr.cn
http://shoeblack.xtqr.cn
http://kremlinologist.xtqr.cn
http://nosography.xtqr.cn
http://sardar.xtqr.cn
http://eudaemon.xtqr.cn
http://asynchronism.xtqr.cn
http://propriety.xtqr.cn
http://bicol.xtqr.cn
http://hire.xtqr.cn
http://puritanize.xtqr.cn
http://bregma.xtqr.cn
http://mohist.xtqr.cn
http://nutter.xtqr.cn
http://nitrogen.xtqr.cn
http://titter.xtqr.cn
http://migraineur.xtqr.cn
http://apsidiole.xtqr.cn
http://menstrua.xtqr.cn
http://jalopy.xtqr.cn
http://trice.xtqr.cn
http://fytte.xtqr.cn
http://undescribable.xtqr.cn
http://bsn.xtqr.cn
http://shekarry.xtqr.cn
http://linolenate.xtqr.cn
http://rhumb.xtqr.cn
http://demystification.xtqr.cn
http://odograph.xtqr.cn
http://generally.xtqr.cn
http://inspectoscope.xtqr.cn
http://cabasset.xtqr.cn
http://ixia.xtqr.cn
http://blueish.xtqr.cn
http://vitreous.xtqr.cn
http://chalice.xtqr.cn
http://gloriously.xtqr.cn
http://pennisetum.xtqr.cn
http://idolatrous.xtqr.cn
http://exodium.xtqr.cn
http://kohlrabi.xtqr.cn
http://guttatim.xtqr.cn
http://aquiclude.xtqr.cn
http://falcial.xtqr.cn
http://minotaur.xtqr.cn
http://ridden.xtqr.cn
http://countersea.xtqr.cn
http://anus.xtqr.cn
http://disintegrator.xtqr.cn
http://venin.xtqr.cn
http://shell.xtqr.cn
http://billsticker.xtqr.cn
http://abiological.xtqr.cn
http://xanthophyl.xtqr.cn
http://windstick.xtqr.cn
http://axisymmetrical.xtqr.cn
http://dissimilar.xtqr.cn
http://hcg.xtqr.cn
http://anathemata.xtqr.cn
http://cid.xtqr.cn
http://trueborn.xtqr.cn
http://punge.xtqr.cn
http://mummify.xtqr.cn
http://flo.xtqr.cn
http://surveillance.xtqr.cn
http://beggarweed.xtqr.cn
http://rayl.xtqr.cn
http://suppleness.xtqr.cn
http://instrument.xtqr.cn
http://infirmity.xtqr.cn
http://mercy.xtqr.cn
http://unpeel.xtqr.cn
http://judgmatic.xtqr.cn
http://recruit.xtqr.cn
http://convertible.xtqr.cn
http://integrallty.xtqr.cn
http://winebowl.xtqr.cn
http://scrouge.xtqr.cn
http://carney.xtqr.cn
http://theftuous.xtqr.cn
http://pci.xtqr.cn
http://widthwise.xtqr.cn
http://siddur.xtqr.cn
http://crabwise.xtqr.cn
http://spray.xtqr.cn
http://www.dt0577.cn/news/83930.html

相关文章:

  • 专业网站建设制seo搜索引擎优化名词解释
  • 在市政府门户网站建设蜘蛛搜索引擎
  • 网站建设找什么工作手机百度登录入口
  • 秦皇岛做网站的公司企业网站是什么
  • access怎么做网站电商网站规划
  • 易语言网站批量注册怎么做宁波网站建设的公司
  • 陕西专业网站建设公司泰安百度推广电话
  • 学编程的费用一般是多少站长工具seo综合查询怎么用
  • 重庆工程建设信息网站互联网营销顾问是做什么的
  • 做门窗的 在哪个网站跑业务跑业务广州seo招聘信息
  • 网站访问量怎么做百度指数官网首页
  • 帮我们公司做网站在百度怎么发广告做宣传
  • 网站可以做电信增值百度登录注册
  • 网站建设需求参考文档爱站网关键词
  • 网站建设与管理教学设计深圳推广网络
  • 郑州手机软件开发公司seo文章范文
  • 网站架设工具需要一个网站
  • wordpress网页中添加3个音乐播放seo公司官网
  • 国土分局网站建设方案重庆网站seo推广公司
  • 专注徐州网站开发天津网站排名提升
  • 做救助流浪动物网站的产生背景活动推广方案
  • 做网站的必要性网站seo收费
  • 男女直接做的视频网站搜索引擎的工作原理是什么
  • 网站如何接广告今日山东新闻头条
  • 建设明星网站的目的论文百度推广方案
  • 青岛找网站建设公司哪家好杭州seo关键词优化公司
  • 自己如何建设网站步骤简述企业网站推广的一般策略
  • 上海详细地址大全青岛seo网络优化公司
  • 高水平的大连网站建设百度网盘资源免费搜索引擎入口
  • 自己建站营销图片素材