zoukankan      html  css  js  c++  java
  • UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 0-3: code point not in range

    1、错误描述

    F:PyCharmWorkSpacecmnvenvScriptspython.exe F:/PyCharmWorkSpace/cmn/venv/numpys/A.py
    [ True  True  True  True]
    F:/PyCharmWorkSpace/cmn/venv/numpys/A.py:7: DeprecationWarning: In future, it will be an error for 'np.bool_' scalars to be interpreted as an index
      E = list(map(hex,A));
    Traceback (most recent call last):
    [1.  4.  6.  8.9]
      File "F:/PyCharmWorkSpace/cmn/venv/numpys/A.py", line 15, in <module>
    [1 4 6 8]
        print(F.byteswap());
    [   72057594037927936 -1585267068834414592 -2372271103717408768]
    [   72057594037927936 -1585267068834414592 -2372271103717408768]
      File "F:PyCharmWorkSpacecmnvenvlibsite-packages
    umpycorearrayprint.py", line 1529, in _array_str_implementation
    ['0x1', '0x1', '0x1', '0x1']
        return array2string(a, max_line_width, precision, suppress_small, ' ', "")
      File "F:PyCharmWorkSpacecmnvenvlibsite-packages
    umpycorearrayprint.py", line 700, in array2string
        return _array2string(a, options, separator, prefix)
      File "F:PyCharmWorkSpacecmnvenvlibsite-packages
    umpycorearrayprint.py", line 472, in wrapper
        return f(self, *args, **kwargs)
      File "F:PyCharmWorkSpacecmnvenvlibsite-packages
    umpycorearrayprint.py", line 505, in _array2string
        lst = _formatArray(a, format_function, options['linewidth'],
      File "F:PyCharmWorkSpacecmnvenvlibsite-packages
    umpycorearrayprint.py", line 826, in _formatArray
        return recurser(index=(),
      File "F:PyCharmWorkSpacecmnvenvlibsite-packages
    umpycorearrayprint.py", line 782, in recurser
        word = recurser(index + (-i,), next_hanging_indent, next_width)
      File "F:PyCharmWorkSpacecmnvenvlibsite-packages
    umpycorearrayprint.py", line 736, in recurser
        return format_function(a[index])
    UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 0-3: code point not in range(0x110000)
    
    Process finished with exit code 1
    

    2、错误原因

          python语言中的numpy包,字符串数组不能交换,不然会报错

    import numpy as np;
    
    A = np.all([[1,2,3,4],[5,6,7,8]], axis=0);
    B = np.array([1,4,6,8.9]);
    C = np.array([1,234,5343], dtype=np.int64);
    D = C.byteswap(inplace=True);
    E = list(map(hex,A));
    F = np.array(['yh','ui','ce','dh']);
    print(A);
    print(B);
    print(B.astype(int));
    print(C);
    print(D);
    print(E);
    print(F.byteswap());

    3、解决办法

          在定义变量F时,调用np.array(),数组中的元素不能是字符串类型

    import numpy as np;
    
    A = np.all([[1,2,3,4],[5,6,7,8]], axis=0);
    B = np.array([1,4,6,8.9]);
    C = np.array([1,234,5343], dtype=np.int64);
    D = C.byteswap(inplace=True);
    E = list(map(hex,A));
    F = np.array([23,45,67,32]);
    print(A);
    print(B);
    print(B.astype(int));
    print(C);
    print(D);
    print(E);
    print(F.byteswap());
  • 相关阅读:
    Native Boot 从一个 VHD 引导系统的相关说明
    bind()函数的深入理解及两种兼容方法分析
    四、CentOS 6.5 上传和安装Nginx
    jQuery 常见操作实现方式
    “贷券” 信贷系统
    注册 Ironic 裸金属节点并部署裸金属实例
    hover()方法
    Uncaught SyntaxError: Inline Babel script: Unexpected token
    Uncaught Error: The `style` prop expects a mapping from style properties to values, not a string
    jquery bind事件
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313683.html
Copyright © 2011-2022 走看看