scipy.io.
hb_read#
- scipy.io.hb_read(path_or_open_file, *, spmatrix=True)[source]#
读取 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