zoukankan      html  css  js  c++  java
  • numpy深浅复制

    In [1]:
    import numpy as np
    
    #Simple assignments make no copy of array objects or of their data.
    a = np.arange(12)
    b = a
    # a and b are two names for the same ndarray object
    print(b is a)
    b.shape = (3,4)
    print (a.shape)
    print (id(a))
    print (id(b))
    
     
    True
    (3, 4)
    4496815328
    4496815328
    
    In [2]:
    #The view method creates a new array object that looks at the same data.
    c = a.view()
    print (c is a)
    c.shape = (2,6)
    print (a.shape)
    c[0,4] = 1234
    print(c)
    print(a)
    
     
    False
    (3, 4)
    [[   0    1    2    3 1234    5]
     [   6    7    8    9   10   11]]
    [[   0    1    2    3]
     [1234    5    6    7]
     [   8    9   10   11]]
    
    In [3]:
    #The copy method makes a complete copy of the array and its data.
    d = a.copy() 
    print (d is a)
    d[0,0] = 9999
    print (d)
    print (a)
    
     
    False
    [[9999    1    2    3]
     [1234    5    6    7]
     [   8    9   10   11]]
    [[   0    1    2    3]
     [1234    5    6    7]
     [   8    9   10   11]]
    
  • 相关阅读:
    mysql int类型 int(11) 和int(2)区别
    mysql 用户 登陆 权限相关
    【转】ext4+delalloc造成单次写延迟增加的分析
    write 系统调用耗时长的原因
    【转】通过blktrace, debugfs分析磁盘IO
    win7 wifi热点
    【SystemTap】 Linux下安装使用SystemTap源码安装SystemTap
    pdflush进程介绍与优化【转】
    How to find per-process I/O statistics on Linux
    oom_killer
  • 原文地址:https://www.cnblogs.com/FinnChan/p/11614120.html
Copyright © 2011-2022 走看看