pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <i id='hvxkg'><tr id='hvxkg'><dt id='hvxkg'><q id='hvxkg'><span id='hvxkg'><b id='hvxkg'><form id='hvxkg'><ins id='hvxkg'></ins><ul id='hvxkg'></ul><sub id='hvxkg'></sub></form><legend id='hvxkg'></legend><bdo id='hvxkg'><pre id='hvxkg'><center id='hvxkg'></center></pre></bdo></b><th id='hvxkg'></th></span></q></dt></tr></i><div class="htjvtrl" id='hvxkg'><tfoot id='hvxkg'></tfoot><dl id='hvxkg'><fieldset id='hvxkg'></fieldset></dl></div>

    1. <legend id='hvxkg'><style id='hvxkg'><dir id='hvxkg'><q id='hvxkg'></q></dir></style></legend>
      <tfoot id='hvxkg'></tfoot>

        <small id='hvxkg'></small><noframes id='hvxkg'>

        • <bdo id='hvxkg'></bdo><ul id='hvxkg'></ul>

        將 numpy 列表數組轉換為 numpy 數組

        Convert a numpy array of lists to a numpy array(將 numpy 列表數組轉換為 numpy 數組)
            <tbody id='DoHgL'></tbody>

            <bdo id='DoHgL'></bdo><ul id='DoHgL'></ul>
              <i id='DoHgL'><tr id='DoHgL'><dt id='DoHgL'><q id='DoHgL'><span id='DoHgL'><b id='DoHgL'><form id='DoHgL'><ins id='DoHgL'></ins><ul id='DoHgL'></ul><sub id='DoHgL'></sub></form><legend id='DoHgL'></legend><bdo id='DoHgL'><pre id='DoHgL'><center id='DoHgL'></center></pre></bdo></b><th id='DoHgL'></th></span></q></dt></tr></i><div class="f5dln5t" id='DoHgL'><tfoot id='DoHgL'></tfoot><dl id='DoHgL'><fieldset id='DoHgL'></fieldset></dl></div>

                <small id='DoHgL'></small><noframes id='DoHgL'>

              1. <legend id='DoHgL'><style id='DoHgL'><dir id='DoHgL'><q id='DoHgL'></q></dir></style></legend>
                  <tfoot id='DoHgL'></tfoot>
                  本文介紹了將 numpy 列表數組轉換為 numpy 數組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一些數據存儲為帶有 dtype=object 的 numpy 數組,我想提取一列列表并將其轉換為 numpy 數組.這似乎是一個簡單的問題,但我發現解決它的唯一方法是將整個事物重鑄為列表列表,然后將其重鑄為 numpy 數組.有沒有更 Pythonic 的方法?

                  I have some data which is stored as a numpy array with dtype=object, and I would like to extract one column of lists and convert it to a numpy array. It seems like a simple problem, but the only way I've found to solve it is to recast the entire thing as a list of lists and then recast it as a numpy array. Is there a more pythonic approach?

                  import numpy as np
                  
                  arr = np.array([[1, ['a', 'b', 'c']], [2, ['a', 'b', 'c']]], dtype=object)
                  arr = arr[:, 1]
                  
                  print(arr)
                  # [['a', 'b', 'c'] ['a', 'b', 'c']]
                  
                  type(arr)
                  # numpy.ndarray
                  type(arr[0])
                  # list
                  
                  arr.shape
                  # (2,)
                  

                  將數組重鑄為 dtype=str 會引發 ValueError,因為它試圖將每個列表轉換為字符串.

                  Recasting the array as dtype=str raises a ValueError since it is trying to convert each list to a string.

                  arr.astype(str)
                  # ValueError: setting an array element with a sequence
                  

                  可以將整個數組重建為列表列表,然后將其轉換為 numpy 數組,但這似乎是一種迂回的方式.

                  It is possible to rebuild the entire array as a list of lists and then cast it as a numpy array, but this seems like a roundabout way.

                  arr_2 = np.array(list(arr))
                  
                  type(arr_2)
                  # numpy.ndarray
                  type(arr_2[0])
                  # numpy.ndarray
                  
                  arr_2.shape
                  # (2, 3)
                  

                  有沒有更好的方法來做到這一點?

                  Is there a better way to do this?

                  推薦答案

                  雖然通過列表的方式比通過 vstack 的方式更快:

                  Though going by way of lists is faster than by way of vstack:

                  In [1617]: timeit np.array(arr[:,1].tolist())
                  ...
                  100000 loops, best of 3: 11.5 μs per loop
                  In [1618]: timeit np.vstack(arr[:,1])
                  ...
                  10000 loops, best of 3: 54.1 μs per loop
                  

                  vstack 正在做:

                  np.concatenate([np.atleast_2d(a) for a in arr[:,1]],axis=0)
                  

                  一些替代方案:

                  In [1627]: timeit np.array([a for a in arr[:,1]])
                  100000 loops, best of 3: 18.6 μs per loop
                  In [1629]: timeit np.stack(arr[:,1],axis=0)
                  10000 loops, best of 3: 60.2 μs per loop
                  

                  請記住,對象數組只包含指向內存中其他位置的列表的指針.雖然 arr 的 2d 特性使得選擇第二列變得容易,但 arr[:,1] 實際上是一個列表列表.并且對其進行的大多數操作都是這樣對待的.reshape 之類的東西不會跨越 object 邊界.

                  Keep in mind that the object array just contains pointers to the lists which are else where in memory. While the 2d nature of arr makes it easy to select the 2nd column, arr[:,1] is effectively a list of lists. And most operations on it treat it as such. Things like reshape don't cross that object boundary.

                  這篇關于將 numpy 列表數組轉換為 numpy 數組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                • <i id='efZgm'><tr id='efZgm'><dt id='efZgm'><q id='efZgm'><span id='efZgm'><b id='efZgm'><form id='efZgm'><ins id='efZgm'></ins><ul id='efZgm'></ul><sub id='efZgm'></sub></form><legend id='efZgm'></legend><bdo id='efZgm'><pre id='efZgm'><center id='efZgm'></center></pre></bdo></b><th id='efZgm'></th></span></q></dt></tr></i><div class="bj5rn5v" id='efZgm'><tfoot id='efZgm'></tfoot><dl id='efZgm'><fieldset id='efZgm'></fieldset></dl></div>
                • <legend id='efZgm'><style id='efZgm'><dir id='efZgm'><q id='efZgm'></q></dir></style></legend>

                    <tbody id='efZgm'></tbody>
                  <tfoot id='efZgm'></tfoot>

                        <small id='efZgm'></small><noframes id='efZgm'>

                            <bdo id='efZgm'></bdo><ul id='efZgm'></ul>
                            主站蜘蛛池模板: 地图标注|微信高德百度地图标注|地图标记-做地图[ZuoMap.com] | 工业PH计|工业ph酸度计|在线PH计价格-合肥卓尔仪器仪表有限公司 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 高考志愿规划师_高考规划师_高考培训师_高报师_升学规划师_高考志愿规划师培训认证机构「向阳生涯」 | 雷蒙磨,雷蒙磨粉机,雷蒙磨机 - 巩义市大峪沟高峰机械厂 | 茶楼装修设计_茶馆室内设计效果图_云臻轩茶楼装饰公司 | 温湿度记录纸_圆盘_横河记录纸|霍尼韦尔记录仪-广州汤米斯机电设备有限公司 | 锯边机,自动锯边机,双面涂胶机-建业顺达机械有限公司 | PTFE接头|聚四氟乙烯螺丝|阀门|薄膜|消解罐|聚四氟乙烯球-嘉兴市方圆氟塑制品有限公司 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 锯边机,自动锯边机,双面涂胶机-建业顺达机械有限公司 | 实体店商新零售|微赢|波后|波后合作|微赢集团 | 手板-手板模型-手板厂-手板加工-生产厂家,[东莞创域模型] | 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 仓储笼_金属箱租赁_循环包装_铁网箱_蝴蝶笼租赁_酷龙仓储笼租赁 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 探伤仪,漆膜厚度测试仪,轮胎花纹深度尺厂家-淄博创宇电子 | 特材真空腔体_哈氏合金/镍基合金/纯镍腔体-无锡国德机械制造有限公司 | 塑钢件_塑钢门窗配件_塑钢配件厂家-文安县启泰金属制品有限公司 深圳南财多媒体有限公司介绍 | 步进电机_agv电机_伺服马达-伺服轮毂电机-和利时电机 | 超声波流量计_流量标准装置生产厂家 _河南盛天精密测控 | 电机保护器-电动机综合保护器-上海硕吉电器有限公司 | 小青瓦丨古建筑瓦丨青瓦厂家-宜兴市徽派古典建筑材料有限公司 | 液压油缸-液压缸厂家价格,液压站系统-山东国立液压制造有限公司 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 锤式粉碎机,医药粉碎机,锥式粉碎机-无锡市迪麦森机械制造有限公司 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 | 动力配电箱-不锈钢配电箱-高压开关柜-重庆宇轩机电设备有限公司 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 | 西安耀程造价培训机构_工程预算实训_广联达实作实操培训 | 太阳能发电系统-太阳能逆变器,控制器-河北沐天太阳能科技首页 | 拉力机-万能试验机-材料拉伸试验机-电子拉力机-拉力试验机厂家-冲击试验机-苏州皖仪实验仪器有限公司 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 | 尊享蟹太太美味,大闸蟹礼卡|礼券|礼盒在线预订-蟹太太官网 | 超声骨密度仪,双能X射线骨密度仪【起草单位】,骨密度检测仪厂家 - 品源医疗(江苏)有限公司 | 北京易通慧公司从事北京网站优化,北京网络推广、网站建设一站式服务商-北京网站优化公司 | 范秘书_懂你的范文小秘书 | 震动筛选机|震动分筛机|筛粉机|振筛机|振荡筛-振动筛分设备专业生产厂家高服机械 | FFU_空气初效|中效|高效过滤器_空调过滤网-广州梓净净化设备有限公司 | 防水套管_柔性防水套管_刚性防水套管-巩义市润达管道设备制造有限公司 | 德国UST优斯特氢气检漏仪-德国舒赐乙烷检测仪-北京泽钏 | 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 江苏全风,高压风机,全风环保风机,全风环形高压风机,防爆高压风机厂家-江苏全风环保科技有限公司(官网) | 天津次氯酸钠酸钙溶液-天津氢氧化钠厂家-天津市辅仁化工有限公司 | 污水处理设备-海普欧环保集团有限公司 |