在这里我发现了一个非常有趣的博客:温度效应的临界阈值和经验方法非常有趣,所以我想在R中实现它的想法.但是,我有德国历史日常温度(15年历史)的多层栅格数据大RasterBrick
对象的日平均温度.根据在灵感的帖子中讨论的经验方法,我需要从我的多层栅格数据构建温度分布.
更新2:可重现的shapefile:
我知道从第三方网站下载shapefile是不实际的,所以在这里我想出了可重复的shapefile来尝试:
library(sf)
library(maps)
library(rgeos)
library(mapdata)
germany <- st_as_sf(map("Germany", plot = FALSE, fill = TRUE))
write_sf(germany, "germany.shp")
Run Code Online (Sandbox Code Playgroud)
为了便于跟进我的帖子,我创建了可重现的栅格数据以便在R中使用.我还提供了来自欧盟统计局网站的德国shapefile; 这里是动态的shapefile(我可以保证链接非常安全,文件非常小):eurostat'formfile,这里是方便的可重现的栅格数据:
可重复的数据
library(raster)
library(lubridate)
library(tidyverse)
r <- raster(xmn=5.75, xmx= 15, ymn = 47.25, ymx =55,res=c(0.25,0.25))
Deu_crop <- do.call(stack,lapply(1:5479,function(i) setValues(r,round(runif(n = ncell(r),min = -10,max = 25)))))
names(Deu_crop) <- paste0('X',gsub('-','.',ymd('1980.01.01') + days(1:5479)))
shp <- shapefile('eurostat_NUTS3/deu_adm_2006.shp')
e <- raster::extract(Deu_crop,shp)
names(e) <- shp$NUTS_ID
Run Code Online (Sandbox Code Playgroud)
因此,为了测试灵感帖子中提供的工作流程,我需要设计几个全局变量,这些变量将用于此处介绍的辅助函数.但我不明白如何设计一些用于完成其工作流程的关键全局变量; 建议定义全局变量,如:w
- 天气数据; tempDat
:特定的汇总天气数据; Trows
:span聚合网格数据; …
我在图像分类任务中使用了泰勒展开式。基本上,首先,像素向量是从 RGB 图像生成的,像素向量中的每个像素值都将用 的泰勒级数展开来近似sin(x)
。在 tensorflow 实现中,我尝试使用 tensorflow 对其进行编码,但是当我尝试通过将张量与扩展项堆叠来创建特征图时仍然遇到一些问题。任何人都可以提供可能的观点,我怎样才能使我目前的尝试更有效率?任何可能的想法?
这是 的泰勒级数的展开项sin(x)
:
这是我目前的尝试:
term = 2
c = tf.constant([1, -1/6])
power = tf.constant([1, 3])
x = tf.keras.Input(shape=(32, 32, 3))
res =[]
for x in range(term):
expansion = c * tf.math.pow(tf.tile(x[..., None], [1, 1, 1, 1, term]),power)
m_ij = tf.math.cumsum(expansion, axis=-1)
res.append(m_i)
Run Code Online (Sandbox Code Playgroud)
但这不太有效,因为我想从每个扩展神经元创建输入特征图delta_1
,delta_2
需要堆叠,我在上面的尝试中没有正确制作,而且我的代码也没有很好地概括。如何以正确的实施方式改进我的上述编码尝试?任何人都可以给我可能的想法或规范的答案来改进我目前的尝试吗?
我正在寻找嵌套 lapply 的有效替代方案,我认为在 R 社区中不赞赏使用嵌套结构。任何人都可以提出可能的想法或方法来避免在自定义函数中使用 Nest lapply 吗?
这是快速可重现的示例:
a <- data.frame(
start=seq(1, by=9, len=18), stop=seq(6, by=9, len=18),
ID=letters[seq(1:18)], score=sample(1:25, 18, replace = FALSE))
b <- data.frame(
start=seq(2, by=11, len=20), stop=seq(8, by=11, len=20),
ID=letters[seq(1:20)], score=sample(1:25, 20, replace = FALSE))
c <- data.frame(
start=seq(4, by=11, len=25), stop=seq(9, by=11, len=25),
ID=letters[seq(1:25)], score=sample(1:25, 25, replace = FALSE))
Run Code Online (Sandbox Code Playgroud)
a.big <- a[a$score >10,]
a.sml <- a[(a$score > 6 & a$score <= 10),]
a.non <- a[a$score < 6,]
a_new <- list('big'=a.big, 'sml'=a.sml) …
Run Code Online (Sandbox Code Playgroud) 在 flask-restplus API 中,我需要对请求 JSON 数据进行验证,其中我已经用api.model
. 基本上我想将输入的 JSON 数据传递给 API 函数,在使用 API 函数之前我必须验证输入的 JSON 数据。为此,我用于RequestParser
执行此任务,但 API 函数期望在验证和解析请求 JSON 后将正确的 JSON 数据作为参数。要进行请求 JSON 验证,首先我必须解析接收到的输入 JSON 数据,解析其 JSON 主体,验证每个,然后将其重建为 JSON 对象,并传递给 API 函数。有没有更简单的方法来做到这一点?
输入 JSON 数据
{
"body": {
"gender": "M",
"PCT": {
"value": 12,
"device": "roche_cobas"
},
"IL6": {
"value": 12,
"device": "roche_cobas"
},
"CRP": {
"value": 12,
"device": "roche_cobas"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我目前在烧瓶中的尝试
from flask_restplus import Api, Namespace, Resource, fields, reqparse, inputs
from flask import Flask, …
Run Code Online (Sandbox Code Playgroud) 我有一堆矢量需要向另一个矢量和.我正在寻找更优雅的矢量添加解决方案,而不是使用'+'运算符.有没有人知道以更舒适的方式做这件事的任何伎俩.谢谢
向量:
a <- c(1,1,0,2,1,0,1,0,1)
b <- c(0,0,1,0,1,1,0,1,0)
c <- c(0,1,1,0,0,2,1,1,1)
Run Code Online (Sandbox Code Playgroud)
我知道做这个的虚拟方式,我期待这样做的优雅
期望的输出:
out <- c(1,2,2,2,2,3,2,2,2)
Run Code Online (Sandbox Code Playgroud)
有效地进行这种操作的任何优雅方式?
r ×3
python ×2
flask ×1
function ×1
json ×1
keras ×1
lapply ×1
performance ×1
raster ×1
tensorflow ×1
time-series ×1
vector ×1