• numpy.reshape


    >>> a = np.arange(6).reshape((3, 2))
    >>> a
    array([[0, 1],
           [2, 3],
           [4, 5]])
    
    >>> np.reshape(a, (2, 3)) # C-like index ordering
    array([[0, 1, 2],
           [3, 4, 5]])
    >>> np.reshape(np.ravel(a), (2, 3)) # equivalent to C ravel then C reshape
    array([[0, 1, 2],
           [3, 4, 5]])
    >>> np.reshape(a, (2, 3), order='F') # Fortran-like index ordering
    array([[0, 4, 3],
           [2, 1, 5]])
    >>> np.reshape(np.ravel(a, order='F'), (2, 3), order='F')
    array([[0, 4, 3],
           [2, 1, 5]])
    
    >>> a = np.array([[1,2,3], [4,5,6]])
    >>> np.reshape(a, 6)
    array([1, 2, 3, 4, 5, 6])
    >>> np.reshape(a, 6, order='F')
    array([1, 4, 2, 5, 3, 6])
    

    One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.

    >>> np.reshape(a, (3,-1))       # the unspecified value is inferred to be 2
    array([[1, 2],
           [3, 4],
           [5, 6]])
    
  • 相关阅读:
    2019年8月22日 星期四(杂谈)
    文件读写
    log4j
    java 读写 xlsx
    mongodb的增删改查
    mongodb安装与简单配置
    mondb的特性
    mongodb 的简单应用
    linux 学习1
    linux 安装MySql
  • 原文地址:https://www.cnblogs.com/yaos/p/14014336.html
Copyright © 2020-2023  润新知