久久久久久久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 列表數(shù)組轉(zhuǎn)換為 numpy 數(shù)組

        Convert a numpy array of lists to a numpy array(將 numpy 列表數(shù)組轉(zhuǎn)換為 numpy 數(shù)組)
            <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 列表數(shù)組轉(zhuǎn)換為 numpy 數(shù)組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一些數(shù)據(jù)存儲為帶有 dtype=object 的 numpy 數(shù)組,我想提取一列列表并將其轉(zhuǎn)換為 numpy 數(shù)組.這似乎是一個簡單的問題,但我發(fā)現(xiàn)解決它的唯一方法是將整個事物重鑄為列表列表,然后將其重鑄為 numpy 數(shù)組.有沒有更 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,)
                  

                  將數(shù)組重鑄為 dtype=str 會引發(fā) ValueError,因為它試圖將每個列表轉(zhuǎn)換為字符串.

                  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
                  

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

                  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)
                  

                  有沒有更好的方法來做到這一點(diǎn)?

                  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
                  

                  請記住,對象數(shù)組只包含指向內(nèi)存中其他位置的列表的指針.雖然 arr 的 2d 特性使得選擇第二列變得容易,但 arr[:,1] 實際上是一個列表列表.并且對其進(jìn)行的大多數(shù)操作都是這樣對待的.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.

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

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

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進(jìn)度躍升至 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 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時,yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進(jìn)度條?)
                • <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>
                            主站蜘蛛池模板: 成人小视频在线 | 欧美成年人视频在线观看 | 成人影院网站ww555久久精品 | 日本成年免费网站 | 91精品欧美久久久久久久 | 超碰免费在线 | 成人免费视频网站在线观看 | 中文字幕日韩一区 | 特黄色一级毛片 | 狠狠操狠狠操 | 欧美一级黄色免费看 | 成人免费视频网站在线看 | 啪啪综合网| 黄色毛片免费看 | 激情欧美日韩一区二区 | 国久久 | 久久国产精品久久国产精品 | 国产亚洲精品美女久久久久久久久久 | 成年人免费看 | 中文字幕在线视频免费视频 | 免费国产精品久久久久久 | 欧美成年网站 | 精品视频一区二区三区 | 午夜小电影 | 视频一区 国产精品 | 亚洲一二三在线观看 | 国产又爽又黄的视频 | 国产日韩视频 | 亚洲视频观看 | 亚洲国产成人精品久久久国产成人一区 | 欧美日韩一区二区在线播放 | 精品粉嫩aⅴ一区二区三区四区 | 国产一区二区三区 | 色频| 亚洲网站在线观看 | 一区二区三区在线看 | 亚洲精品区 | 午夜午夜精品一区二区三区文 | 亚洲精品在线看 | 欧美一级特黄aaa大片在线观看 | 99精品视频在线 |