zoukankan      html  css  js  c++  java
  • numpy reshape -1

    >>> import numpy as np
    >>> x = np.arange(12)
    >>> x
    array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
    >>> x.reshape(2,3,2,1)
    array([[[[ 0],
             [ 1]],
    
            [[ 2],
             [ 3]],
    
            [[ 4],
             [ 5]]],
    
    
           [[[ 6],
             [ 7]],
    
            [[ 8],
             [ 9]],
    
            [[10],
             [11]]]])
    >>> x.reshape(2,2,1,3)
    array([[[[ 0,  1,  2]],
    
            [[ 3,  4,  5]]],
    
    
           [[[ 6,  7,  8]],
    
            [[ 9, 10, 11]]]])
    >>> x.reshape(1,3,2,2)
    array([[[[ 0,  1],
             [ 2,  3]],
    
            [[ 4,  5],
             [ 6,  7]],
    
            [[ 8,  9],
             [10, 11]]]])
    >>>
    >>> x
    array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
    >>> y= x.reshape(1,3,2,2)
    >>> y
    array([[[[ 0, 1],
    [ 2, 3]],
    
    [[ 4, 5],
    [ 6, 7]],
    
    [[ 8, 9],
    [10, 11]]]])
    >>> y.shape
    (1, 3, 2, 2)
    >>> y.shape[0]
    1
    >>> y.reshape(y.shape[0],-1)
    array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])
    >>> y
    array([[[[ 0, 1],
    [ 2, 3]],
    
    [[ 4, 5],
    [ 6, 7]],
    
    [[ 8, 9],
    [10, 11]]]])
    >>> y.reshape(1,-1)
    array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])
    >>> y.reshape(2,-1)
    array([[ 0, 1, 2, 3, 4, 5],
    [ 6, 7, 8, 9, 10, 11]])
    >>> y.reshape(3,-1)
    array([[ 0, 1, 2, 3],
    [ 4, 5, 6, 7],
    [ 8, 9, 10, 11]])
    >>> y.reshape(4,-1)
    array([[ 0, 1, 2],
    [ 3, 4, 5],
    [ 6, 7, 8],
    [ 9, 10, 11]])
    >>> y.reshape(10,-1)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: cannot reshape array of size 12 into shape (10,newaxis)
    >>> y.reshape(5,-1)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: cannot reshape array of size 12 into shape (5,newaxis)
    >>> y.shape
    (1, 3, 2, 2)
    >>>
    

      

      

  • 相关阅读:
    [thinkphp] 是如何输出一个页面的
    [thinkphp] 获取根目录绝对路径
    onethink 插件模板定位
    win7 安全模式开启声音
    百度贴吧楼层评论地址
    第一天问题
    [php] 解析JSON字符串
    NDK编译时两 .so之间调用问题
    CDN问题积累
    C++模板特化
  • 原文地址:https://www.cnblogs.com/morganh/p/8616612.html
Copyright © 2011-2022 走看看