我在Windows 10机器上安装了Anaconda 5.0.1.我的电脑上有一些Jupyter笔记本,我想将它们与Jupyter联系起来,以避免每次打开Jupyter并导航到笔记本文件夹.那可能吗?
PS我问这里是因为我觉得这个问题对程序员来说更有意义,但是如果你认为它更适合SuperUser,我会把它标记为迁移.
我需要读取模板文件test.txt
,修改内容,然后将带有名称的修改后的副本foo`i`.in
(i
是迭代编号)写入磁盘.由于我需要多次执行此操作(一百万次并不罕见),因此优选有效的解决方案.模板文件是这样的:
1
bar.out
70.000000000000000
2.000000000000000
14.850000000000000
8000.000000000000000
120.000000000000000
60.000000000000000
0.197500000000000
0.197500000000000
2.310000000000000
0.200000000000000
0.000000000000000
1.000000000000000
0.001187700000000
22.000000000000000
1.400000000000000
1.000000000000000
0.010000000000000
100
0.058600000000000
-0.217000000000000
0.078500000000000
-0.110100000000000
30
500.000000000000000
T
Run Code Online (Sandbox Code Playgroud)
我不需要修改所有行,只需修改其中一些行.具体而言,我需要修改bar.out
到bar`i`.out
这里i
是一个迭代指数.我还需要使用以下值修改一些数字行:
parameters <- data.frame(index = c(1:10, 13:16, 21:22), variable = c("P1",
"P2", "T1", "s", "D", "L", "C1", "C2", "VA",
"pw", "m", "mw", "Cp", "Z", "ff_N", "ff_M"),
value = c(65, 4, 16.85, 7900, 110, 60, 0.1975, .1875, 2.31,
0.2, 0.0011877, 22.0, …
Run Code Online (Sandbox Code Playgroud) 按照对象.我在Windows 7 64位下运行Python 2.7.10.我将C:\ Python27\Scripts添加到我的PATH,我可以运行pip
,但它无法安装模块.例如
pip install numpy
Run Code Online (Sandbox Code Playgroud)
给
Collecting numpy
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after
connection broken by 'ProtocolError('Connection aborted.', gaierror(11004,'getaddrinfo failed'))': /simple/numpy/
Run Code Online (Sandbox Code Playgroud)
它会一直重试并失败,然后退出
Could not find a version that satisfies the requirement numpy (from versions:
)
No matching distribution found for numpy
Run Code Online (Sandbox Code Playgroud)
可能我是在防火墙后面,但我很失望,因为我可以安装R
完好的软件包install.packages
,我不明白为什么我不能用Python做同样的事情.如果我手动安装包(在这种情况下numpy
,从这里
关于使用,我会错过什么pip
?
编辑:根据评论中的建议,我从numpy下载了nwhy的.whl文件,导航到下载目录并执行
pip install numpy-1.10.1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Run Code Online (Sandbox Code Playgroud)
我只有
numpy-1.10.1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl is not a supported wheel on this platform.
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我一直在玩R Markdown,我非常喜欢它,因为在我的每次分析之后,我都需要写一份详细说明结果的(Word)报告.使用R Markdown,代码和报告是相同的文档,因此很容易记住,我选择在代码中的某个点执行分析B,因为之前的分析结果为A.
但是,我无法在R Studio中的R Markdown中设置断点,这严重限制了执行高效调试的可能性.这意味着最终我只能使用Markdown进行非常简单的分析,其中R代码非常简单,我不需要调试它,或者我可以手动调试它.这是可以预料的,也就是众所周知R Markdown只能用于简单分析?或者有解决方案吗?
我有一个庞大的数据框架,我想做一些图来了解不同变量之间的关联.我不能用
pairs(data)
Run Code Online (Sandbox Code Playgroud)
,因为那会给我400多块情节.然而,我有一个特别感兴趣的响应变量.因此,我想对所有变量绘制y,这会将绘图的数量从n ^ 2减少到n.你能告诉我怎么做吗?谢谢
编辑:我为了清楚起见添加了一个例子.假设我有数据帧
foo=data.frame(x1=1:10,x2=seq(0.1,1,0.1),x3=-7:2,x4=runif(10,0,1))
Run Code Online (Sandbox Code Playgroud)
我的响应变量是x3.然后我想生成连续排列的四个图,分别是x1对x3,x2对x3,x3的直方图,最后是x4对x3.我知道如何制作每个情节
plot(foo$x1,foo$x3)
plot(foo$x2,foo$x3)
hist(foo$x3)
plot(foo$x4,foo$x3)
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何连续排列它们.此外,如果有一种方法可以自动生成所有n个绘图,而不必每次都调用命令图(或hist),那将会很棒.当n = 4时,它不是一个大问题,但我通常处理n = 20 +变量,所以它可能是一个拖累.
我经常使用B样条进行回归.到目前为止,我从来不需要bs
详细了解输出:我只选择我感兴趣的模型,并适合它lm
.但是,我现在需要在外部(非R)代码中重现b样条模型.那么,矩阵产生的含义是什么bs
?例:
x <- c(0.0, 11.0, 17.9, 49.3, 77.4)
bs(x, df = 3, degree = 1) # generate degree 1 (linear) B-splines with 2 internal knots
# 1 2 3
# [1,] 0.0000000 0.0000000 0.0000000
# [2,] 0.8270677 0.0000000 0.0000000
# [3,] 0.8198433 0.1801567 0.0000000
# [4,] 0.0000000 0.7286085 0.2713915
# [5,] 0.0000000 0.0000000 1.0000000
# attr(,"degree")
# [1] 1
# attr(,"knots")
# 33.33333% 66.66667%
# 13.30000 38.83333
# attr(,"Boundary.knots")
# [1] 0.0 77.4
# …
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
import numpy as np
from numba import jit
Nx = 15
Ny = 1000
v = np.ones((Nx,Ny))
v = np.reshape(v,(Nx*Ny))
A = np.random.rand(Nx*Ny,Nx*Ny,5)
B = np.random.rand(Nx*Ny,Nx*Ny,5)
C = np.random.rand(Nx*Ny,5)
@jit(nopython=True)
def dotplus(B, v, C):
return np.dot(B, v) + C
k = 2
D = dotplus(B[:,:,k], v, C[:,k])
Run Code Online (Sandbox Code Playgroud)
我收到以下警告,我猜它指的是数组B[:,:,k]
和v
:
NumbaPerformanceWarning: np.dot() is faster on contiguous arrays, called on (array(float64, 2d, A), array(float64, 1d, C))
return np.dot(B, v0) + C
Run Code Online (Sandbox Code Playgroud)
有没有办法让两个数组连续,这样Numba就可以加速代码?
PS,如果您想知道 的含义k
,请注意这只是 MRE。在实际代码中,在循环内针对不同的值(因此,和的不同切片)dotplus …
样本数据框:
df <- data.frame(x=rep(1:10,4),y=rnorm(40),Case=rep(c("B","L","BC","R"),each=10))
Run Code Online (Sandbox Code Playgroud)
我可以用自己的方面绘制每个时间序列:
ggplot(df,aes(x=x,y=y,color=Case)) + geom_line()+facet_wrap(~Case,nr=2,nc=2)
Run Code Online (Sandbox Code Playgroud)
现在,假设我想将facet顺序更改为(从左上角开始,沿着行向右下方)"L","B","R","BC".这里因此通常的建议是做这个.但是,如果我重新排序因子级别,
Case
曲线的颜色也会改变.是否可以重新排序刻面,而不改变曲线颜色的顺序?我知道这听起来像一个奇怪的问题.问题是我的报告是一项正在进行中的工作,在我已向同事和管理层展示的报告的旧版本中,有多个图表或多或少像这样(没有facet_wrap
):
ggplot(df,aes(x=x,y=y,color=Case)) + geom_line()
Run Code Online (Sandbox Code Playgroud)
换句话说,到现在为止,人们习惯将"B"与红色相关联.如果我重新排序,"L"将为红色,"B"为绿色,依此类推.我已经可以听到抱怨了......任何出路都没有?
我需要gather_
在数据帧的所有列上,除了一个.例:
# I want to generate a dataframe whose column names are the letters of the alphabet. If you know of a simpler way, let me know!
foo <- as.data.frame(matrix(runif(100), 10, 10))
colnames(foo) <- letters[1:10]
Run Code Online (Sandbox Code Playgroud)
现在,假设我想收集除列之外的所有列e
.这不起作用:
mycol <- "e"
foo_melt <- gather_(foo, key = "variable", value = "value", -mycol)
#Error in -mycol : invalid argument to unary operator
Run Code Online (Sandbox Code Playgroud)
这将:
column_list <- colnames(foo)
column_list <- column_list[column_list != mycol]
foo_melt <- gather_(foo, key = "variable", value = "value", …
Run Code Online (Sandbox Code Playgroud) 我需要处理由其他人编写的相对较大的R代码.代码没有文档,它被分成无数个文件,每个文件都可以包含一个或多个函数.原作者没有使用Makefile,所以没有关于什么叫什么的文档.
作为第一步,我想建立一个树形图.我的意思是一个树,其根是主文件,内部节点是调用的各种文件,叶子(终端节点)是不调用其他文件中定义的函数的文件.有没有办法自动完成?图片输出会很棒,但即使是文本文件也可以.R Studio解决方案也可以.
编辑:显然我的描述不够清楚,因此我添加了一个非常简单(实际上是琐碎的)示例.假设我有4个源文件main.r
,foo.r
,bar.r
和blargh.r
,所有在同一文件夹(真正的情况下具有约50个文件中的所有"整齐"存储在相同的文件夹红润,与输入/输出文件一起).内容main.r
是:
# main.r
source("foo.r")
source("bar.r")
source("blargh.r")
foo()
bar()
Run Code Online (Sandbox Code Playgroud)
foo.r
:
# foo.r
foo <- function(){
print("I'm foo")
blargh()
}
Run Code Online (Sandbox Code Playgroud)
bar.r
:
# bar.r
bar <- function(){
print("I'm bar")
blargh()
}
Run Code Online (Sandbox Code Playgroud)
blargh.r
# blargh.r
blargh <- function(){
print("I'm blargh")
}
Run Code Online (Sandbox Code Playgroud)
我需要生成的是这样的图表:
main.r
¦--foo.r
¦ ¦
¦ °--blargh.r
¦
°--bar.r
¦
°--blargh.r
Run Code Online (Sandbox Code Playgroud) r ×7
numpy ×2
python ×2
anaconda ×1
bspline ×1
call-graph ×1
debugging ×1
diagram ×1
dot-product ×1
facet-wrap ×1
file-io ×1
ggplot2 ×1
jupyter ×1
matrix ×1
numba ×1
performance ×1
pip ×1
plot ×1
r-markdown ×1
reshape2 ×1
rstudio ×1
tidyr ×1
windows ×1