栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 奇怪的知识

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 奇怪的知识

文章目录
  • 向量梯度
  • 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;
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/960648.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号