我需要在服务器上安装python才能运行脚本,但是服务器无法访问互联网。
服务器可以访问可以访问Internet *的本地网络。我想使用pip通过此处指定的本地网络目录来管理软件包。
如何在离线状态的Windows机器上安装pip,python及其依赖项,以便可以使用上述链接中指定的pip来管理所需的软件包?
*对于清晰度:我无权镜像,修改或以其他方式获取信息,直接从Internet通过本地网络传递信息。
在低长度迭代次数的限制中考虑以下操作,
d = (3, slice(None, None, None), slice(None, None, None))
In [215]: %timeit any([type(i) == slice for i in d])
1000000 loops, best of 3: 695 ns per loop
In [214]: %timeit any(type(i) == slice for i in d)
1000000 loops, best of 3: 929 ns per loop
Run Code Online (Sandbox Code Playgroud)
设置为a list比使用生成器表达式快25%?
为什么这样设置为a list是一个额外的操作.
注意:在两次运行中,我都获得了警告:The slowest run took 6.42 times longer than the fastest. This could mean that an intermediate result is being cachedI
在该特定测试中,list()结构更快,直到 …
施加np.ndarray如下所示的周期性边界条件
np.ndarray围绕n-dimensions 中的边界包裹 python 的索引n维环面的周期性边界条件下面给出一个例子和反例:
a = np.arange(27).reshape(3,3,3)
b = Periodic_Lattice(a) # A theoretical class
# example: returning a scalar that shouldn't be accessible
print b[3,3,3] == b[0,0,0] # returns a scalar so invokes wrapping condition
try: a[3,3,3] # the value is out of bounds in the original np.ndarray
except: print 'error'
# counter example: returning a slice
try: …Run Code Online (Sandbox Code Playgroud) 我有两个清单:
a = [1,1,1]
b = [[2,2,2],[3,3,3]]
Run Code Online (Sandbox Code Playgroud)
我想在前面加上a上b的代码创建一个行:
result = [[1,1,1],[2,2,2],[3,3,3]]
Run Code Online (Sandbox Code Playgroud)
我想保留a并b在此过程中你不能只做:
b[:0] = [a]
Run Code Online (Sandbox Code Playgroud) 下面的例子似乎暗示了我不明白的运行时优化
\n谁能解释这种行为以及它如何适用于更一般的情况?
\n考虑以下简单(示例)函数
\ndef y(x): # str output\n y = 1 if x else 0\n return str(y)\n\ndef _y(x): # no str\n y = 1 if x else 0\n return y\nRun Code Online (Sandbox Code Playgroud)\n假设我想将函数应用于y列表中的所有元素
l = range(1000) # test input data\nRun Code Online (Sandbox Code Playgroud)\n操作map必须遍历列表中的所有元素。将函数分解为双map精度函数明显优于单个map函数,这似乎违反直觉
%timeit map(str, map(_y, l))\n1000 loops, best of 3: 206 \xc2\xb5s per loop\n\n%timeit map(y, l)\n1000 loops, best of 3: 241 \xc2\xb5s per loop\n …Run Code Online (Sandbox Code Playgroud) 定义多项式
# a specific polynomial x**0 + x**1 + x**2 + x**3
p = [1, -2.8176255165067872, -0.97639120853458261, -0.86023870029448335]
Run Code Online (Sandbox Code Playgroud)
这是一个很好的例子来证明这种差异,
import numpy as np
r1 = np.roots(p); r2 = np.polynomial.polynomial.polyroots(p)
f = lambda x: np.sum([x**i*j for i,j in enumerate(p)])
print "{:>10} {:>10}".format("roots","polyroots")
for i,j in zip(r1, r2): # test should return 0
print "{:10.5f} {:10.5f}".format(np.abs(f(i)),np.abs(f(j)))
Run Code Online (Sandbox Code Playgroud)
输出显然不为零
roots polyroots
46.41221 0.00000
1.97595 0.00000
1.97595 0.00000
Run Code Online (Sandbox Code Playgroud)
在比较中,Mathematica正确地获得了根源:
fn[x_] := 1.` - 2.817625516506788` x - 0.97639120853458261` x^2 - …Run Code Online (Sandbox Code Playgroud) 构建一系列日志返回的最快和最优雅的解决方案是什么?
问题主要在于映射一个函数,该函数将第i个和第(i + 1)个元素作为数组中每个元素的输入.
对于函数和简单数组,我可以定义日志返回如下:
import numpy as np
ar = np.random.rand(10)
f_logR = lambda ri, rf: np.log(rf) - np.log(ri)
logR = np.asarray([f_logR(ar[i], rf) for i,rf in enumerate(ar[1:])])
Run Code Online (Sandbox Code Playgroud)
但是,我正在从单个numpy元素构建一个列表,然后再将它转换回numpy数组.
我也是以相当野蛮的方式访问元素,因为我对生成器函数或numpy内部的经验很少.
我最近发现我可以_用作变量.
是否有一个特定的协议何时将其用作变量名?应该__用吗?
来自deeplearning.net和Theano库的示例,_在定义theano.scan()操作时有一种趋势...
values, _ = theano.scan(power_of_2,
outputs_info = T.constant(1.),
non_sequences = max_value,
n_steps = 1024)
Run Code Online (Sandbox Code Playgroud) 为什么如下
$ echo "test\|String" | sed 's/(?!\||\\)./&./g'
test\|String
Run Code Online (Sandbox Code Playgroud)
不生产:
t.e.s.t.\|S.t.r.i.n.g.
Run Code Online (Sandbox Code Playgroud)
我测试了正则表达式代码,它在我的测试中正确选取字符串
我希望它能做到以下几点:
$ echo "test\|String" | sed 's/(?!\||\\)./&./g'
t.e.s.t.\|S.t.r.i.n.g.
Run Code Online (Sandbox Code Playgroud) python ×8
numpy ×3
iteration ×2
list ×2
performance ×2
boundary ×1
caching ×1
coding-style ×1
dictionary ×1
financial ×1
indexing ×1
installation ×1
offline ×1
optimization ×1
pip ×1
pipe ×1
polynomials ×1
prepend ×1
python-2.7 ×1
regex ×1
sed ×1
setuptools ×1
sorting ×1
variables ×1