scipy.io.

hb_read#

scipy.io.hb_read(path_or_open_file, *, spmatrix=True)[原始碼]#

讀取 HB 格式檔案。

參數:
path_or_open_filepath-like 或 file-like

如果是 file-like 物件,則直接使用。否則,會在讀取前開啟。

spmatrixbool,選用 (預設值: True)

如果 True,則傳回稀疏 coo_matrix。否則傳回 coo_array

傳回值:
datacsc_array 或 csc_matrix

從 HB 檔案讀取的資料,以稀疏陣列形式呈現。

註解

目前不支援完整的 Harwell-Boeing 格式。支援的功能如下:

  • 組裝的、非對稱的、實數矩陣

  • 指標/索引的整數

  • 浮點數值的指數格式,以及整數格式

範例

我們可以讀取和寫入 harwell-boeing 格式檔案

>>> from scipy.io import hb_read, hb_write
>>> from scipy.sparse import csr_array, eye
>>> data = csr_array(eye(3))  # create a sparse array
>>> hb_write("data.hb", data)  # write a hb file
>>> print(hb_read("data.hb", spmatrix=False))  # read a hb file
<Compressed Sparse Column sparse array of dtype 'float64'
    with 3 stored elements and shape (3, 3)>
    Coords  Values
    (0, 0)  1.0
    (1, 1)  1.0
    (2, 2)  1.0