我想要一个用于快速、可视化输入的滑块,但也需要一个用于精确计算的相应数字输入。我已设法将滑块绑定value到input$,因此它们将遵循数字输入中写入的内容。但是,我似乎无法让它以相反的方式工作。
用户界面
numericInput("num_l",
label = "Beam length in m.",
value = 10),
numericInput("num_a",
label = "Choose position, where to apply force, starting from left, in m.",
value = input$slider_a), # THIS DOESN'T WORK
numericInput("num_x",
label = "Calculate the deflection, at position starting from left, in m.",
value = input$slider_x), # NEITHER DOES THIS
Run Code Online (Sandbox Code Playgroud)
服务器
output$slider <- renderUI({
tagList( # Need this for multiple reactive sliders
sliderInput("slider_a",
label = "Load force position:",
min = 0,
max = …Run Code Online (Sandbox Code Playgroud) 如果我设置shade_lowest = False,颜色栏仍然包含最低级别(purple-ish).有没有通用的方法来完全删除它?
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
a = np.random.normal(0, 1, 100)
b = np.random.normal(0, 1, 100)
fig, ax = plt.subplots()
sns.kdeplot(a, b, shade = True, shade_lowest = False, cmap = "viridis", cbar = True, n_levels = 4, ax = ax)
plt.show()
Run Code Online (Sandbox Code Playgroud) 我一直在互联网上搜索,试图了解并行处理。
他们似乎都假设我有某种循环函数在运行,例如在 N 个核心之间划分并随后组合的数据集的每第 N 行,并且我指向许多并行化apply()函数。
(警告,下面丑陋的代码)
我的情况是我已经在表格上
tempJob <- myFunction(filepath, string.arg1, string.arg2)
Run Code Online (Sandbox Code Playgroud)
其中路径是文件位置,字符串参数是对数据进行排序的各种方式。
我目前的工作流程只是积累了很多
tempjob1 <- myFunction(args)
tempjob2 <- myFunction(other args)
...
tempjobN <- myFunction(some other args here)
# Make a list of all temporary outputs in the global environment
temp.list <- lapply(ls(pattern = "temp"), get)
# Stack them all
df <- rbindlist(temp.list)
# Remove all variables from workspace matching "temp"
rm(list=ls(pattern="temp"))
Run Code Online (Sandbox Code Playgroud)
这些作业是完全独立的,原则上可以在 8 个独立的 R 实例中运行(尽管我猜这会很麻烦)。我如何将前 8 个作业分成 8 个内核,每当一个内核完成其工作并将处理过的数据集返回到全局环境时,它就会简单地执行下一个作业。
假设我想对关闭灯时记录的数据拟合一条直线。现在我不小心把灯打开了,我的数据从数据点 101 开始有一个恒定的偏移量。
我怎样才能适应这个?我尝试为 x 加入一个条件,但出现错误
ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()
请记住取消注释其余代码(以遇到错误)。
import numpy as np
from scipy import optimize
import matplotlib.pyplot as plt
d1 = np.random.normal(0,0.1, 100)
d2 = np.random.normal(3,0.1, 100)
x = np.arange(0,200)
y = np.concatenate((d1,d2))
plt.plot(x, y)
# def line(x, a, b, offset):
# if x < 101:
# y = a * x + b
# else:
# y = (a * x + b) + offset
# return y
#
# popt, pcov = optimize.curve_fit(line, xdata …Run Code Online (Sandbox Code Playgroud) 我有一个给定的功能
def unnorm(x, alpha, beta):
return (1 + alpha * x + beta * x ** 2)
Run Code Online (Sandbox Code Playgroud)
然后我将其集成以查找范围内的归一化常量,并将其转换为采用相同参数的lambda函数unnorm.现在,为了创建一个合适的对象,我将这些函数组合在一起:
def normalized(x, alpha, beta):
return unnorm(x, alpha, beta) * norm(x, alpha, beta)
Run Code Online (Sandbox Code Playgroud)
这很好,但仍然有重复,并从全局命名空间中提取名称.
如何以更干净的方式组合这两个功能,而无需重新编写参数?例如
def normalized(func, normalizer):
return func * normalizer
Run Code Online (Sandbox Code Playgroud)
完整代码:
import sympy
import numpy as np
import inspect
def normalize_function(f, xmin, xmax):
"""
Normalizes function to PDF in the given range
"""
# Get function arguments
fx_args = inspect.getfullargspec(f).args
# Convert to symbolic notation
symbolic_args = sympy.symbols(fx_args)
# …Run Code Online (Sandbox Code Playgroud) 本质上,我这样做:
a = True
b = False
ls = [a, b]
a = False
print(ls)
> [True, False]
Run Code Online (Sandbox Code Playgroud)
发生的事情是,a在第一次包含之后,发生的任何事情都会从列表中分离出来。有什么方法可以a以干净的方式更新并让列表自行更新?
当然,我可以简单地做ls[0] = False和被完成。但是在一个包含许多活动部件的大型项目中,我想避免非描述性的括号索引。
我假设我可以对实例化的类做一些凌乱的构造,然后迭代属性,但这听起来像是一团糟。或者是吗?
这里总新手.
我有一个输出写入公式的结果,变量基于输入
output$text_calc <- renderText({
paste("The result is =", input$num_W * input$num_l - input$slider_a... )
})
Run Code Online (Sandbox Code Playgroud)
为了避免我的大脑爆炸长公式,我如何将输入定义为单个字母变量?我试过l <- input$num_l哪个给了我
"没有主动反应上下文就不允许操作.(你试图做一些只能在反应式表达式或观察者内部完成的事情.)"
放置reactive({})代码给出了
错误:无法将类型'闭包'强制类型为'character'类型的向量
来自R,我天真地尝试过
dfE_fitted['E_after'] = dfE_fitted['E_before']
Run Code Online (Sandbox Code Playgroud)
那给了我
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
Run Code Online (Sandbox Code Playgroud)
很公平,我会尝试那样:
dfE_fitted.loc[:,'E_after'] = dfE_fitted['E_before']
Run Code Online (Sandbox Code Playgroud)
这给了我
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py:337: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self.obj[key] = _infer_fill_value(value)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/indexing.py:517: SettingWithCopyWarning:
A value is trying to be set on a copy of a …Run Code Online (Sandbox Code Playgroud) 我的图像看起来像这样,有一些较大的杂质/曝光过度的斑点。通常,它们是否被检测到并不重要,因为测量是时间解析的,因此它们稍后会被删除。
然而,我对尽可能多的小点感兴趣——尽可能快。skimage.feature.peak_local_max做得非常好,并且很容易在不同的数据上使用,因为不需要花太多时间进行强度缩放。
但问题是,由于某种原因,大点会带来非常强烈的积极影响。
import skimage.io
import skimage.feature
import skimage.morphology
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
def plotRoi(spots, img_ax, color, radius):
patches = []
for spot in spots:
y, x = spot
c = plt.Circle((x, y), radius)
patches.append(c)
img_ax.add_collection(PatchCollection(patches, facecolors = "None", edgecolors = color, alpha = 0.3, linewidths = 1))
img = skimage.io.imread("/Path/to/img.png")
img = img[:,:,0]
fig, ax = plt.subplots()
ax.imshow(img, cmap = "Greys")
spots = skimage.feature.peak_local_max(img, min_distance = 0, exclude_border = True, num_peaks = 2000) …Run Code Online (Sandbox Code Playgroud)