最近,Jupyter(笔记本和实验室)开始打印任何内容,就好像我单独执行每一行一样。它过去打印执行的最后一行的输出,但现在它打印所有内容,如下所示。
我可以通过执行例如 来抑制这种情况_ = axs[0].plot(~~~),但是在每行末尾添加分号并没有帮助。我已经重新安装了 Anaconda 但没有任何改变。
我在 MBP 2018 15" 上使用 macOS 10.14.6,在 MS Edge 87.0.664.47 上使用 Python 3.8(基本上是当前 Anaconda 安装的所有内容,无需任何额外安装)。
编辑:更准确地说,任何具有未分配给变量
的返回值的代码行总是被打印。以前,只有当每一行是代码的最后一行时,才会“打印”每一行。无论使用什么软件包,例如 numpy 或 pandas,都会发生这种奇怪的行为:

(仅供参考,可复制文本:
import numpy as np
import pandas as pd
def add_with_return(arr):
arr += 1
return arr
a = np.arange(10)
b = pd.DataFrame(dict(value=a))
a, b
add_with_return(a)
c = np.linspace(0, 1)
Run Code Online (Sandbox Code Playgroud)
)
编辑2:
我使用的软件包版本
$ jupyter --version
jupyter core : 4.6.3
jupyter-notebook : 6.1.4
qtconsole : 4.7.7
ipython …Run Code Online (Sandbox Code Playgroud) 我T_0在 python 代码的顶部定义了一个变量,并希望通过F2MS VS Code更改此变量。
T_0 = 10
T_1 = T_0 + 1
print(T_1)
Run Code Online (Sandbox Code Playgroud)
但首先,我收到一条错误消息Refactoring library rope is not installed。
然后我在这里找到了答案。适当更改后,我收到了一条新的错误消息Refactor failed. Rename refactoring should be performed on resolvable python identifiers.。
如何在 MS VS Code 的 python 代码中重命名变量?
我使用的是 Python 3.6,VS Code 1.19.2。
我想做一个通用函数,它以函数对象作为参数。
最简单的情况之一:
import numpy as np
import numba as nb
@nb.njit()
def test(a, f=np.median):
return f(a)
test(np.arange(10), np.mean)
Run Code Online (Sandbox Code Playgroud)
给出错误,虽然test(np.arange(10))按预期工作。
错误:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
non-precise type pyobject
[1] During: typing of argument at <ipython-input-54-52cead0f097d> (5)
File "<ipython-input-54-52cead0f097d>", line 5:
def test(a, f=np.median):
return f(a)
^
This error may have been caused by the following argument(s):
- argument 1: cannot determine Numba type of <class 'function'>
This is not usually a problem with Numba …Run Code Online (Sandbox Code Playgroud) 我正在尝试将2D表面适合数据。更具体地说,我想找到一个将像素坐标映射到波长坐标的函数,就像FITCOORDS在IRAF中一样。
举例来说,我想test在以下代码片段中找到适合数组的内容:
import numpy as np
from astropy.modeling.models import Chebyshev2D
from astropy.modeling.fitting import LevMarLSQFitter
#%%
test = np.array([[7473, 7040, 6613, 6183, 5753, 5321, 4888],
[7474, 7042, 6616, 6186, np.nan, 5325, 4893],
[7476, 7044, 6619, 6189, 5759, 5328, 4897],
[7479, 7047, np.nan, 6192, 5762, 5331, 4900]])
grid_pix, grid_wave = np.mgrid[:4, :7]
fitter = LevMarLSQFitter()
c2_init = Chebyshev2D(x_degree=3, y_degree=3)
c2_fit = fitter(c2_init, grid_wave, grid_pix, test)
print(c2_fit)
Run Code Online (Sandbox Code Playgroud)
ResultI 在Python 3.6 上astropy 2.0.2和numpy 1.13.3以下:
Model: Chebyshev2D …Run Code Online (Sandbox Code Playgroud)