使用autodoc
和类似的工具允许从源文档字符串编译文档.但是,它似乎不允许函数或类docstrings中的任意ReST节标题,并产生错误:
SEVERE: Unexpected section title.
我在尝试记录numpy样式指南时遇到了类似的问题numpydoc
:没有sphinx的意外部分标题是问题,
numpy如何将docstrings处理成sphinx文档中的参数
然而,在这里,我实际上是在记录JavaScript,并且只想在文档字符串中使用任意的节标题和ReST.
Javascript docstring api:sphinx jsapidoc
Python(和 ipython)具有非常强大的事后调试功能,允许在回溯的每个范围内进行变量检查和命令执行。up/down 调试器命令允许更改最终异常的堆栈跟踪的帧,但是__cause__
按照raise ... from ...
语法定义的那个异常呢?
Python 3.7.6 (default, Jan 8 2020, 13:42:34)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: def foo():
...: bab = 42
...: raise TypeError
...:
In [2]: try:
...: foo()
...: except TypeError as err:
...: barz = 5
...: raise ValueError from err
...:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-dd046d7cece0> in <module>
1 try: …
Run Code Online (Sandbox Code Playgroud) 按照散景文档制作网格图时,如果我使用figure
'slegend
关键字参数,我会在每个子图中得到一个图例。我怎样才能获得整个网格图的共享图例?此外,我怎么能在 4 个子图中的 3 个之间获得共享的图例?
我希望以下代码仅设置绘图 y 范围的上限,但下限也莫名其妙地设置为 0:
import bokeh.plotting as bkp
import numpy as np
bkp.output_file("/tmp/test_plot.html")
fig = bkp.figure(y_range=[None, 100]) # plot y range: 0-100
# fig = bkp.figure() # plot y range: 50-100
fig.line(np.linspace(0, 1, 200), np.random.random(200)*50+50) # number range: 50-100
bkp.save(fig)
Run Code Online (Sandbox Code Playgroud)
为什么会出现这种情况?仅设置 1 个范围界限的最简单方法是什么?
我正在尝试使用填充数组 np.nan
import numpy as np
print np.version.version
# 1.10.2
combine = lambda real, theo: np.vstack((theo, np.pad(real, (0, theo.shape[0] - real.shape[0]), 'constant', constant_values=np.nan)))
real = np.arange(20)
theoretical = np.linspace(0, 20, 100)
result = combine(real, theoretical)
np.any(np.isnan(result))
# False
Run Code Online (Sandbox Code Playgroud)
检查result
,似乎而不是np.nan
,阵列正在填补-9.22337204e+18
.这里发生了什么?我该怎么np.nan
办?
根据 numpy 文档,take
\nit 与 \xe2\x80\x9cfancy\xe2\x80\x9d 索引(使用数组索引数组)执行相同的操作。但是,如果您需要沿给定轴的元素,它会更容易使用。
然而,与“花式”或常规 numpy 索引不同,使用切片作为索引似乎不受支持:
\n\nIn [319]: A = np.arange(20).reshape(4, 5)\n\nIn [320]: A[..., 1:4]\nOut[320]: \narray([[ 1, 2, 3],\n [ 6, 7, 8],\n [11, 12, 13],\n [16, 17, 18]])\n\nIn [321]: np.take(A, slice(1, 4), axis=-1)\nTypeError: long() argument must be a string or a number, not \'slice\'\n
Run Code Online (Sandbox Code Playgroud)\n\n使用仅在运行时已知的轴上的切片来索引数组的最佳方法是什么?
\n当我打电话时:
np.fromstring('3 3 3 0', sep=' ')
Run Code Online (Sandbox Code Playgroud)
它返回
array([ 3., 3., 3., 0.])
Run Code Online (Sandbox Code Playgroud)
由于默认为,sep=''
我希望以下调用返回相同的结果:
np.fromstring('3330')
Run Code Online (Sandbox Code Playgroud)
但是它引起了
ValueError: string size must be a multiple of element size
Run Code Online (Sandbox Code Playgroud)
为什么是这样?什么是得到的最Python的方式array([ 3., 3., 3., 0.])
从'3330'
?