稀疏矩阵的逐元素exp() [英] Element wise exp() of scipy sparse matrix

查看:110
本文介绍了稀疏矩阵的逐元素exp()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的稀疏csc_matrix x.我想对它做elementwise exp().基本上,我想要得到的结果与使用numpy.exp(x.toarray())获得的结果相同.但是我做不到(我的记忆不允许我将稀疏矩阵转换成数组).有没有出路?预先感谢!

I have a very big sparse csc_matrix x. I want to do elementwise exp() on it. Basically what I want is to get the same result as I would have got with numpy.exp(x.toarray()). But I can't do that(my memory won't allow me to convert the sparse matrix into an array). Is there any way out? Thanks in advance!

推荐答案

如果没有存储x.toarray()的内存,则没有存储要存储的输出的内存.输出不会稀疏.实际上,除非您的输入中包含负无穷大,否则输出可能不会有单个0.

If you don't have the memory to hold x.toarray(), you don't have the memory to hold the output you're asking for. The output won't be sparse; in fact, unless your input has negative infinities in it, the output probably won't have a single 0.

计算exp(x)-1可能会更好,因为它很简单

It'd probably be better to compute exp(x)-1, which is as simple as

x.expm1()

这篇关于稀疏矩阵的逐元素exp()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆