简体   繁体   English

Numpy / Polyfit - 禁止打印英特尔MKL错误消息

[英]Numpy / Polyfit - Suppress printing of Intel MKL Error message

I'm computing a polyfit multiple times during a program, and some of my inputs are np.nan and are going to get the algorithm problems. 我在程序中多次计算polyfit ,我的一些输入是np.nan ,并且会得到算法问题。 I know this, and in this application I don't care. 我知道这一点,在这个应用程序中我不在乎。

When things mess up, this is printed to the console: 当事情搞砸时,会打印到控制台:

Intel MKL ERROR: Parameter 4 was incorrect on entry to DELSD.

I simply want to suppress this error. 我只是想抑制这个错误。 I've already tried: 我已经尝试过了:

import warnings
warnings.simplefilter('ignore', np.RankWarning)
warnings.simplefilter('ignore', np.ComplexWarning)
warnings.filterwarnings('ignore', "Intel MKL ERROR")

Which suppresses some warnings, but not the Intel MKL one. 这抑制了一些警告,但不是英特尔MKL。 I simply want to keep it from printing in the console (since it breaks up the other status messages I'm printing). 我只是想阻止它在控制台中打印(因为它打破了我正在打印的其他状态消息)。

The following should trigger the problem: 以下应该触发问题:

import numpy as np
def line_fit(R, X):
    num_rows = np.shape(R)[0]
    p = np.zeros(num_rows)
    for i in range(num_rows):
        temp = np.polyfit(R[i, :], X[i, :], 1)
        p[i] = temp[1]
    return p
temp = np.array((((198.652-76.1781j),(132.614-43.8134j),(115.042-41.2485j),(91.7754-39.1649j),(78.8538-37.389j),(67.8769-34.6342j)),
((np.nan),(1671.79-796.522j),(1206.44-824.202j),(654.572-682.673j),(438.175-559.025j),(303.624-452.122j)),
((np.nan-1j*np.nan),(1671.32-794.931j),(1198.71-803.533j),(649.574-624.276j),(443.286-530.36j),(308.609-438.738j))))
R = np.real(temp)
X = np.imag(temp)
coeff = line_fit(R, X)

Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)], NumPy 1.8.0 Python 2.7.6(默认,2013年11月10日,19:24:24)[MSC v.1500 64位(AMD64)],NumPy 1.8.0

If a function decides to print an error message directly to stdout/stderr without using the normal Python error reporting mechanism (ie exception handling and warnings), there's little you can do to stop it from doing so. 如果函数决定直接向stdout / stderr打印错误消息而不使用普通的Python错误报告机制(即异常处理和警告),那么你几乎无法阻止它这样做。 If it really annoys you, you can apparently suppress writing to stderr altogether. 如果它真的让你烦恼,你可以完全压制写入stderr。 There is a solution in another SO question as to how to do it temporarily (eg just for this function): Suppress stdout / stderr print from Python functions . 在另一个SO问题中有一个关于如何临时执行的解决方案(例如,仅用于此函数): 从Python函数中抑制stdout / stderr打印 Obviously if you do this, you're also going to miss all the relevant outputs from this function, too, so use it with caution. 显然,如果你这样做,你也会错过这个函数的所有相关输出,所以要谨慎使用它。

The error 错误

Intel MKL ERROR: Parameter 4 was incorrect on entry to DELSD 英特尔MKL错误:进入DELSD时参数4不正确

occurs when you have Nan or Inf value in your input. 当输入中有Nan或Inf值时会发生。 Please check and impute it. 请检查并加以估算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM