我使用样条插值来平滑时间序列,并且还想在图中添加水平线.但似乎有一个问题不在我的掌握之中.任何帮助都会非常有帮助.这是我有的:
annual = np.arange(1,21,1)
l = np.array(value_list) # a list with 20 values
spl = UnivariateSpline(annual,l)
xs = np.linspace(1,21,200)
plt.plot(xs,spl(xs),'b')
plt.plot([0,len(xs)],[40,40],'r--',lw=2)
pylab.ylim([0,200])
plt.show()
Run Code Online (Sandbox Code Playgroud)
问题似乎与我[0,len(xs)]用于水平线绘图有关.
我有一个for loop在每次迭代后生成一个数据帧.我想将所有数据框附加在一起,但发现它很困难.以下是我正在尝试的,请建议如何解决它:
d = NULL
for (i in 1:7) {
# vector output
model <- #some processing
# add vector to a dataframe
df <- data.frame(model)
}
df_total <- rbind(d,df)
Run Code Online (Sandbox Code Playgroud) 我有一个外部可执行文件,我试图从Python脚本运行.CMD可执行文件运行但不生成输出.可能在生成输出之前退出.有关如何延迟退出直到产生输出的任何建议?
import subprocess, sys
from subprocess import Popen, PIPE
exe_str = r"C:/Windows/System32/cmd C:/temp/calc.exe"
parent = subprocess.Popen(exe_str, stderr=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud) 我的代码工作正常,直到我将Numpy更新为1.13.1.现在我收到以下错误
IndexError: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4
Run Code Online (Sandbox Code Playgroud)
...在这一行被抛出:
m = arr[np.diff(np.cumsum(arr) >= sum(arr) * i)]
Run Code Online (Sandbox Code Playgroud)
我似乎无法绕过它.有什么建议?
这是我的示例代码:
a = [1,2,3,4,5]
l = [0.85,0.90]
s = sorted(a, reverse = False)
arr = np.array(s)
for i in l:
m = arr[np.diff(np.cumsum(arr) >= sum(arr) * i)]
Run Code Online (Sandbox Code Playgroud) 我正在尝试根据条件从列表中获取样本。这应该很容易做到,但我无法做到以下几点:
a = [2,4,5,9,1,6,4]
b = 6
c = [x for x in a if a < b]
Run Code Online (Sandbox Code Playgroud)
我基本上需要一个新列表,它应该包含小于 6 的值。有什么建议吗?
我有 16 个子图,希望在每个子图中包含以下内容:
ax1.axvline(x=0.5, ymin=0.0, ymax=1.0, color='k', linestyle='--', alpha=0.3)
ax1.axhline(y=0.5, xmin=0.0, xmax=1.0, color='k', linestyle='--', alpha=0.3)
Run Code Online (Sandbox Code Playgroud)
运行一个循环来为所有子图提供它们似乎比使用 32 行更可行,但简单的字符串连接不起作用,例如
for i in xrange(1,17,1):
# then try to use i for each ax -- this isn't practical
Run Code Online (Sandbox Code Playgroud)
有什么建议么?