久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>
                            主站蜘蛛池模板: 日本午夜免费福利视频 | 自拍偷拍亚洲欧美 | 天天躁日日躁狠狠躁2018小说 | 亚洲欧美激情精品一区二区 | 国产精品资源在线 | 欧美www在线观看 | 成人免费毛片在线观看 | 久久人 | 国产高清在线精品 | 日韩免费视频 | 欧美成人一区二区 | 国产视频二区 | 久久毛片| 正在播放亚洲 | 一区二区日韩 | 91黄在线观看 | 中文字幕欧美一区 | 午夜久久久| 久久九精品| 午夜视频一区 | 欧美日韩国产精品一区二区 | 欧美国产激情 | 国产日韩欧美电影 | 免费观看av网站 | 色眯眯视频在线观看 | 亚洲欧美另类在线观看 | 在线精品一区二区 | 国内自拍真实伦在线观看 | av在线影院 | 亚洲国产欧美国产综合一区 | 91精品在线播放 | 国产精品高潮呻吟久久 | 免费精品久久久久久中文字幕 | 一级毛片视频在线 | 久久国产成人 | 第一福利社区1024 | 午夜免费成人 | 无码日韩精品一区二区免费 | 日韩在线视频网址 | 久久亚洲视频 | 国产高清在线观看 |