是否有一个numpy内置来做类似以下的事情?也就是说,获取一个列表d并返回一个列表,filtered_d其中删除了基于某些假定的点分布的任何外围元素d.
import numpy as np
def reject_outliers(data):
m = 2
u = np.mean(data)
s = np.std(data)
filtered = [e for e in data if (u - 2 * s < e < u + 2 * s)]
return filtered
>>> d = [2,4,5,1,6,5,40]
>>> filtered_d = reject_outliers(d)
>>> print filtered_d
[2,4,5,1,6,5]
Run Code Online (Sandbox Code Playgroud)
我说'类似',因为函数可能允许变化的分布(泊松,高斯等)和变化的异常阈值(如m我在这里使用的那样).
我创建一个这样的命名元组:
from collections import namedtuple
spam = namedtuple('eggs', 'x, y, z')
ham = spam(1,2,3)
Run Code Online (Sandbox Code Playgroud)
然后我可以用例如火腿访问元素
>>> ham.x
1
>>> ham.z
3
Run Code Online (Sandbox Code Playgroud)
在翻译中,
>>> ham
eggs(x=1, y=2, z=3)
Run Code Online (Sandbox Code Playgroud)
但是,如果我只想得到"蛋"呢?我能想到的唯一方法是
>>> ham.__repr__.split('(')[0]
'eggs'
Run Code Online (Sandbox Code Playgroud)
但这似乎有点凌乱.这样做有更清洁的方法吗?
如果不使用私有方法无法访问它,为什么命名元组有这种"蛋"方面?
在Vim中定义符号时,屏幕左侧会出现一列.
来自Vim的帮助:
当为文件定义符号时,Vim将自动添加一个包含两个
字符的列以显示它们.当最后一个符号未放置时,该列将
再次消失.
是否有可能在仍有标志定义的情况下移除色谱柱?
理想情况下,我想打开/关闭列.
编辑:我得到的方程式参考包含几个错误.我在这里修好了.解决方案现在可能真的有意义!
当两层流体流过地形时,取决于流速的相对大小和流体中的波速,存在许多不同的解决方案.

这些被称为"超临界","次临界"和"关键"(前两个我在这里称为"超临界").
以下等式定义了(h,U0)参数空间中临界行为和临界行为之间的界限:
我想消除d_1c(即我不在乎它是什么)并找到这些方程的解决方案(h, U_0).
简化因素:
d_0我想用Enthought分配中的模块来解决这个问题(numpy,scipy,sympy),但是真的不知道从哪里开始.消除变量d1c确实让我感到困惑.
这是python中的方程式:
def eq1(h, U0, d1c, d0=0.1):
f = (U0) ** 2 * ((d0 ** 2 / d1c ** 3) + (1 - d0) ** 2 / (1 - d1c - d0) ** 3) - 1
return f
def eq2(h, U0, d1c, d0=0.1):
f = 0.5 * (U0) ** 2 * ((d0 ** 2 / d1c ** 2) - (1 …Run Code Online (Sandbox Code Playgroud) 我试图用鼻子编写测试,使用多处理计算得出的东西.
我有这个目录结构:
code/
tests/
tests.py
Run Code Online (Sandbox Code Playgroud)
tests.py看起来像这样:
import multiprocessing as mp
def f(i):
return i ** 2
pool = mp.Pool()
out = pool.map(f, range(10))
def test_pool():
"""Really simple test that relies on the output of pool.map.
The actual tests are much more complicated, but this is all
that is needed to produce the problem."""
ref_out = map(f, range(10))
assert out == ref_out
if __name__ == '__main__':
test_pool()
Run Code Online (Sandbox Code Playgroud)
从code目录运行,python tests/tests.py 传递.
nosetests tests/tests.py 未能完成.它启动,但永远不会通过呼叫pool.map …
我正在尝试改进 Markdown 文档中数学的语法突出显示。
Multimarkdown 使用括号\\[ .. \\]和\\( .. \\)分别表示显示和内联数学。我想用 TeX 突出显示这些内容。
这是我到目前为止所得到的:
syntax include @tex syntax/tex.vim
syn region displaymaths matchgroup=mkdMaths start = "\\\\\[" end="\\\\\]" contains=@tex
syn region inlinemaths matchgroup=mkdMaths start = "\\\\(" end="\\\\)" contains=@tex
hi def link mkdMaths SpecialComment
Run Code Online (Sandbox Code Playgroud)
问题是括号内的内容没有被 tex.vim 提取为数学,因为它没有包含在$ .. $. 有没有办法解决这个问题?我认为我想在这里使用的是syntax/tex.vim 中的texMath 组。
有什么方法可以强制将括号的内容解释为 Tex 数学吗?