当前位置: 首页 > news >正文

重庆网站建设开发公司大学生网站建设例题答案

重庆网站建设开发公司,大学生网站建设例题答案,网站免费制作教程,wordpress wp play浅拷贝的时候#xff0c;修改原来的对象#xff0c;深拷贝的对象不会发生改变。 对象的赋值 对象的赋值实际上是对象之间的引用#xff1a;当创建一个对象#xff0c;然后将这个对象赋值给另外一个变量的时候#xff0c;python并没有拷贝这个对象#xff0c;而只是拷贝了…浅拷贝的时候修改原来的对象深拷贝的对象不会发生改变。 对象的赋值 对象的赋值实际上是对象之间的引用当创建一个对象然后将这个对象赋值给另外一个变量的时候python并没有拷贝这个对象而只是拷贝了这个对象的引用。 aList [kel,abc,123] print(aList, id(aList)) bList aListbList.append(add)print(aList, id(aList)) print(bList, id(bList)) ([kel, abc, 123], 139637569314688) ([kel, abc, 123, add], 139637569314688) ([kel, abc, 123, add], 139637569314688) 同样 numpy 下的数据结构与数据类型的转换np.array vs. np.asarray np.array() 是深拷贝np.asarray() 是浅拷贝 两者主要的区别在于array默认复制一份对象asarray不会执行这一动作。 def asarray(a, dtypeNone, orderNone):return array(a, dtype, copyFalse, orderorder) 示例一 import numpy as np arr1np.ones((3,3)) arr2np.array(arr1) arr3np.asarray(arr1) print(arr2 is arr1) print(arr3 is arr1) print(arr1:,arr1, id(arr1)) print(arr2:,arr2, id(arr2)) print(arr3:,arr3, id(arr3)) False True (arr1:, array([[ 1., 1., 1.],[ 1., 1., 1.],[ 1., 1., 1.]]), 139637569303856) (arr2:, array([[ 1., 1., 1.],[ 1., 1., 1.],[ 1., 1., 1.]]), 139637569303776) (arr3:, array([[ 1., 1., 1.],[ 1., 1., 1.],[ 1., 1., 1.]]), 139637569303856) 示例二 import numpy as np arr1np.ones((3,3)) arr2np.array(arr1) arr3np.asarray(arr1) arr1[1]2 print(arr1:,arr1, id(arr1)) print(arr2:,arr2, id(arr2)) print(arr3:,arr3, id(arr3)) (arr1:, array([[ 1., 1., 1.],[ 2., 2., 2.],[ 1., 1., 1.]]), 139637569303296) (arr2:, array([[ 1., 1., 1.],[ 1., 1., 1.],[ 1., 1., 1.]]), 139637569303376) (arr3:, array([[ 1., 1., 1.],[ 2., 2., 2.],[ 1., 1., 1.]]), 139637569303296) 对象的复制 当你想修改一个对象而且让原始的对象不受影响的时候那么就需要使用到对象的复制对象的复制可以通过三种方法实现 a、 使用切片操作进行拷贝--slice operation b、 使用工厂函数进行拷贝list/dir/set--factoryfunction c、 copy.copy--use copymodule 在复制的时候使用的是浅拷贝复制了对象但是对象中的元素依然使用引用。 person [name,[savings,100.00]] hubby person[:] #切片操作 wifey list(person) #使用工厂函数[id(x) for x in person,hubby,wifey] print(The person is:, person, id(person)) print(The hubby is:, hubby, id(hubby)) print(The wifey is:, wifey, id(wifey)) (The person is:, [name, [savings, 100.0]], 139637569566984) (The hubby is:, [name, [savings, 100.0]], 139637569544848) (The wifey is:, [name, [savings, 100.0]], 139637569405656) print(The person inside is:, [id(x) for x in person]) print(The hubby inside is:, [id(x) for x in hubby]) print(The wifey inside is:, [id(x) for x in wifey]) (The person inside is:, [139639860076144, 139637569544344]) (The hubby inside is:, [139639860076144, 139637569544344]) (The wifey inside is:, [139639860076144, 139637569544344]) hubby[0] kel wifey[0] jane hubby[1][1] 50.0 print(The person is:, person, id(person)) print(The hubby is:, hubby, id(hubby)) print(The wifey is:, wifey, id(wifey)) (The person is:, [name, [savings, 50.0]], 139637570044992) (The hubby is:, [kel, [savings, 50.0]], 139637569460344) (The wifey is:, [jane, [savings, 50.0]], 139637569406160) print(The person inside is:, [id(x) for x in person]) print(The hubby inside is:, [id(x) for x in hubby]) print(The wifey inside is:, [id(x) for x in wifey]) (The person inside is:, [139639860076144, 139637569810016]) (The hubby inside is:, [139637569356104, 139637569810016]) (The wifey inside is:, [139637569378272, 139637569810016]) 在使用浅拷贝的时候发现引用的id都是相同的但是字符串的id却发生了变化是因为在python中字符串是不可变的从而在每次进行修改的时候都是新建一个对象从而引用发生了变化。 copy模块 浅拷贝和深拷贝的操作都可以在copy模块中找到其实copy模块中只有两个函数可用copy进行浅拷贝操作而deepcopy进行深拷贝操作 #1 import copy aList [1,kel,[1,2,3]] print(The aList is:, aList, id(aList))shadeList copy.copy(aList) print(The shadeList is:, shadeList, id(shadeList))deepList copy.deepcopy(aList) print(The deepList is:, deepList, id(deepList))aList[2].append(kel)print(The aList is:, aList, id(aList))print(The shadeList is:, shadeList, id(shadeList))print(The deepList is:, deepList, id(deepList)) (The aList is:, [1, kel, [1, 2, 3]], 139639722291712) (The shadeList is:, [1, kel, [1, 2, 3]], 139639722170344) (The deepList is:, [1, kel, [1, 2, 3]], 139637569586096) (The aList is:, [1, kel, [1, 2, 3, kel]], 139639722291712) (The shadeList is:, [1, kel, [1, 2, 3, kel]], 139639722170344) (The deepList is:, [1, kel, [1, 2, 3]], 139637569586096) #2 import copy aList [1,kel,[1,2,3]] print(The aList is:, aList, id(aList))shadeList copy.copy(aList) print(The shadeList is:, shadeList, id(shadeList))deepList copy.deepcopy(aList) print(The deepList is:, deepList, id(deepList))shadeList[2].append(kel)print(The aList is:, aList, id(aList))print(The shadeList is:, shadeList, id(shadeList))print(The deepList is:, deepList, id(deepList)) (The aList is:, [1, kel, [1, 2, 3]], 139637569846448) (The shadeList is:, [1, kel, [1, 2, 3]], 139637569406520) (The deepList is:, [1, kel, [1, 2, 3]], 139637569407240) (The aList is:, [1, kel, [1, 2, 3, kel]], 139637569846448) (The shadeList is:, [1, kel, [1, 2, 3, kel]], 139637569406520) (The deepList is:, [1, kel, [1, 2, 3]], 139637569407240) #3 import copy aList [1,kel,[1,2,3]] print(The aList is:, aList, id(aList))shadeList copy.copy(aList) print(The shadeList is:, shadeList, id(shadeList))deepList copy.deepcopy(aList) print(The deepList is:, deepList, id(deepList))deepList[2].append(kel) print(The deepList is:, deepList, id(deepList))print(The aList is:, aList, id(aList))print(The shadeList is:, shadeList, id(shadeList)) (The aList is:, [1, kel, [1, 2, 3]], 139637569460776) (The shadeList is:, [1, kel, [1, 2, 3]], 139637569461496) (The deepList is:, [1, kel, [1, 2, 3]], 139637569585592) (The deepList is:, [1, kel, [1, 2, 3, kel]], 139637569585592) (The aList is:, [1, kel, [1, 2, 3]], 139637569460776) (The shadeList is:, [1, kel, [1, 2, 3]], 139637569461496) 参考文献 numpy 下的数据结构与数据类型的转换np.array vs. np.asarray numpy中array和asarray的区别 python中的深拷贝与浅拷贝
http://wiki.neutronadmin.com/news/269000/

相关文章:

  • 企业网站报价方案下载兰州专业做网站的公司哪家好
  • 昭通网站制作wordpress的文件权限设置方法
  • 已经有域名 如何建设网站安徽网站建设seo优化
  • 网站的优化公司超酷网站模板
  • 旅游电子商务网站设计谷歌推广网站建设
  • 网站建设与管理学什么让网站对搜索引擎友好
  • 火狐搜索引擎seosem有什么区别
  • 网站推广软件下载安装免费苏州网站建设方法
  • 动态 静态 网站地图知名的设计网站
  • 经典手机网站建筑人才网官网96877
  • 自助网站建设开发网络培训思想汇报大学生
  • 照明公司网站制作网站备案期间可以建站
  • 网站开发模块查相似备案通
  • 在婚恋网站做销售好吗郑州开发软件公司
  • 做电影网站多少钱2003网站服务器建设中
  • 怎样做营销型网站开发者选项长期开启会怎样
  • 推广网站实例百度云官网入口
  • 网站建设哪家go好国内简洁网站
  • 深圳设计大学网站建设seo优化
  • 深圳大型商城网站建设炫酷的企业网站
  • 塘沽网站制作公司新闻类软文营销案例
  • 全网网站建设网站建设的整体流程有哪些
  • 网站开发学校有哪些北京梵客装饰公司地址电话
  • wordpress站内统计插件江西电信网站备案
  • 北京 工业网站建设公司排名哈尔滨网站seo公司
  • 上海高端网站定设计模板怎么设置
  • 网站建设英文术语网站开发工作时间
  • 不备案的网站可以做竞价吗吉林省建设信息管理平台
  • 什么叫网站外链wordpress加载完再显示图片
  • 制作手机wap网站工具蝴蝶传媒网站推广