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)
    >>>
    

      

      

  • 相关阅读:
    Go语言版本的helloworld
    编译Elasticsearch源码
    Intellij IDEA将java源码打成jar包
    搭建Elasticsearch集群常见问题
    棣小天儿的第一个python程序
    Json反序列化Map的key不能是Object
    mac本配置python环境
    Timestamp解析0000-00-00 00:00:00报格式错误
    Spring-Mybatis配置多数据源
    mysql新建数据库时的collation选择(转)
  • 原文地址:https://www.cnblogs.com/morganh/p/8616612.html
Copyright © 2011-2022 走看看