- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
如何以可移植格式保存/加载 scipy 稀疏 csr_matrix
? scipy 稀疏矩阵是在 Python 3(Windows 64 位)上创建的,可以在 Python 2(Linux 64 位)上运行。最初,我使用了 pickle(协议(protocol) = 2 和 fix_imports = True),但这在从 Python 3.2.2(Windows 64 位)到 Python 2.7.2(Windows 32 位)的过程中不起作用并得到了错误:
TypeError: ('data type not understood', <built-in function _reconstruct>, (<type 'numpy.ndarray'>, (0,), '[98]')).
接下来,尝试了 numpy.save
和 numpy.load
以及 scipy.io.mmwrite()
和 scipy。 io.mmread()
并且这些方法都不起作用。
最佳答案
编辑: scipy 0.19 现在有 scipy.sparse.save_npz
和 scipy.sparse.load_npz
.
from scipy import sparse
sparse.save_npz("yourmatrix.npz", your_matrix)
your_matrix_back = sparse.load_npz("yourmatrix.npz")
对于这两个函数,file
参数也可以是类似文件的对象(即 open
的结果)而不是文件名。
得到了 Scipy 用户组的答复:
A csr_matrix has 3 data attributes that matter:
.data
,.indices
, and.indptr
. All are simple ndarrays, sonumpy.save
will work on them. Save the three arrays withnumpy.save
ornumpy.savez
, load them back withnumpy.load
, and then recreate the sparse matrix object with:
new_csr = csr_matrix((data, indices, indptr), shape=(M, N))
例如:
def save_sparse_csr(filename, array):
np.savez(filename, data=array.data, indices=array.indices,
indptr=array.indptr, shape=array.shape)
def load_sparse_csr(filename):
loader = np.load(filename)
return csr_matrix((loader['data'], loader['indices'], loader['indptr']),
shape=loader['shape'])
关于python - 以可移植数据格式保存/加载 scipy sparse csr_matrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8955448/
我处理来自 AVFrame.data 的原始数据。此帧的像素格式为 AV_PIX_FMT_YUV420P。我想了解此数据位于哪个值范围内。 似乎 UV(在 YUV 方案中)必须在 [-128, 128
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 去年关闭。 Improve this questio
Google Web Toolkits (GWT) RPC 调用的数据格式如何以及 IsSerializable 对象如何传输。我知道 Java Serializable 传输某种二进制格式,但是 G
我打算建立一个简单的音频接口(interface)。为此,我只想知道 ASIO 驱动程序通常以哪种格式将数据传递给程序?我无法从规范中找出这一点,也无法在其他地方找到它。我不想编写自己的驱动程序,我只
我正在编写一个平滑流客户端应用程序。在服务器端(带有Media Services扩展的IIS 7)上,我有一堆ISMV和ISMA文件,这些文件是使用Expression Encoder pro 4预先
我使用 JSON.stringify 和 JQuery.ajax() 将以下 JSON 对象从 .jsp 页面传递到 java servlet: {"bin":[{"binId":"0","binDe
我有一些来自 VLM telnet 服务的数据: show media : ( 1 broadcast - 0 vod ) cam1 type : br
我们正在导出公钥和私钥。私钥将由用 Magic 编写的非 .net 软件使用。开发人员对导出 key 的格式有疑问。是否有白皮书或其他资源来解释导出数据的格式? 最佳答案 关于导出的 blob 类型的
如何在 Altair 中创建多线图? 特别是,我有一个 pandas 数据框,如下所示: Commit Author Date Week Adds
我的数据格式类似于此示例中使用的 flare.json: 我只是想知道 d3 可缩放图表使用什么函数 来获取这种格式的数据 在 flare.json 中是这样的 { name: "stuff",
我正在尝试创建一些 JSON 用于使用 Highcharts 显示图表 http://www.highcharts.com/ 我复制了他们的一个例子: http://www.highcharts.co
我被要求编写一个读取 BSDF data format defined by Zemax 的函数此类文件的示例可在以下页面找到:BSDF file example 如果可能的话,我想只使用标准的 if
我为 CoreML 将 UIImage 转换为 CVPixelBuffer,但我想更改 RGB 像素,如 R/1.5、G/2、B/2.5。 我可以使用assumingMemoryBound(to :
我正在开发一个项目,我想展示网站中的各种文件如何相互交互。我认为使用 D3 这将是一个相当简单的任务,但现在我想知道我的 json 数据是如何排列的。这是我的数据示例: { "pages" : [{
我正在使用 Apache POI 构建一些 Excel 文件,我想确保某些单元格的类型为“Number”。 我尝试了以下方法: style.setDataFormat(HSSFDataForm
我有一些具有小数属性的实体。这些实体的属性显示在我整个 UI 的多个位置。 目前我发现自己在做: litWeight.Text = person.Weight.ToString("0.00"); 无处
首先介绍三个注解: @JsonAutoDetect (method/field):作用于方法或字段,用来表明,当生成json的时候忽略有该annotation的方法或字段 @JsonIgnore 过滤
我是 Azure 的新手,一直在使用 Azure Monitor 和 AZ Sentinel 进行日志记录和分析部分。我的审核日志从 AZ VM 中托管的第三方供应商安全设备流向 Syslog VM。
我有一些代码,例如: CellStyle cs2 = wb.createCellStyle(); CellStyle cs4 = wb.createCellStyle(); cs4.setDataFo
我正在尝试提取 YourKit 的“线程” View 中显示的数据(关于线程状态;主要是当每个线程“等待”或“可运行”时)。我已使用命令行导出实用程序为其支持的所有 View 生成所有格式。 导出目录
我是一名优秀的程序员,十分优秀!