- 向量梯度
- pip 报错 'UnicodeDecodeError: 'gbk' codec can't decode byte 0x98 in position 1130: illegal multibyte sequence'
- 解决
向量梯度
- vector = [a, b, c, d, e, f]
- 边界元素: a的梯度= (b-a)/1; f的梯度=(f-e)/1
- 中间元素: b的梯度= (c-a)/2; 其他中间元素类似
- 例子:
vector = [3, 4, 7, 8, 1, 6, 5] np.gradient(vector) Out[4]: array([ 1., 2., 2., -3., -1., 2., -1.])pip 报错 ‘UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x98 in position 1130: illegal multibyte sequence’
- 报错如下:
...
File "C:Usersx407AppDataLocalProgramsPythonPython38-32libconfigparser.py", line 697, in read
self._read(fp, filename)
File "C:Usersx407AppDataLocalProgramsPythonPython38-32libconfigparser.py", line 1017, in _read
for lineno, line in enumerate(fp, start=1):
UnicodeDecodeError: 'gbk' codec can't decode byte 0x98 in position 1130: illegal multibyte sequence
解决
- 在文件 C:Usersx407AppDataLocalProgramsPythonPython38-32libconfigparser.py 679 行将代码改成:
def read(self, filenames, encoding='utf-8'): # encoding=None, 这就是679 行
"""Read and parse a filename or an iterable of filenames.
Files that cannot be opened are silently ignored; this is
designed so that you can specify an iterable of potential
configuration file locations (e.g. current directory, user's
home directory, systemwide directory), and all existing
configuration files in the iterable will be read. A single
filename may also be given.
Return list of successfully read files.
"""
if isinstance(filenames, (str, bytes, os.PathLike)):
filenames = [filenames]
read_ok = []
for filename in filenames:
try:
with open(filename, encoding=encoding) as fp:
self._read(fp, filename)
except OSError:
continue
if isinstance(filename, os.PathLike):
filename = os.fspath(filename)
read_ok.append(filename)
return read_ok
- 就是编码指定成 utf-8;



