csr_matrix与ndarray类型互转
2024-09-08 19:10:20
ndarry 转 csr_matrix
>>> import numpy as np
>>> import scipy.sparse
>>> my_matrix = scipy.sparse.csr_matrix((2,2))
>>> my_array = my_matrix.A
>>> type(my_array)
numpy.ndarray
1
2
3
4
5
6
7
csr_matrix 转 ndarray
>>> import numpy as np
>>> from scipy import sparse
>>> A = np.array([[1,2,0],[0,0,3],[1,0,4]])
>>> A
array([[1, 2, 0],
[0, 0, 3],
[1, 0, 4]])
>>> sA = sparse.csr_matrix(A) # Here's the initialization of the sparse matrix.
>>> sA
<3x3 sparse matrix of type '<type 'numpy.int32'>'
with 5 stored elements in Compressed Sparse Row format>
>>> print sA
(0, 0) 1
(0, 1) 2
(1, 2) 3
(2, 0) 1
(2, 2) 4
最新文章
- ajax分页与组合查询配合使用
- HLS视频点播&;直播初探
- java之数组
- Test Controller Tool
- 锋利的Jquery解惑系列(二)------插件开发大总结
- bzoj1799
- Linux鸟哥的私房菜(3)— 总体规划和磁盘分区 读书笔记
- 修改tomcat的get方法的参数长度
- C# 异步编程2 EAP 异步程序开发
- js求和运算在可变参数的情况下ES3、ES5和ES6的写法区别
- 网站robots.txt &; sitemap.xml
- Shader 屏幕后期特效 Shake(震屏)&;Wave(波纹)
- org.hibernate.MappingException: class com.itheima.domain.Customer.java not found while looking for property: cust_id 	at org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.
- Groovy 类名称赋值为变量使用(newInstance &; new)
- #WEB安全基础 : HTTP协议 | 0x6 初识HTTP报文
- ODAC(V9.5.15) 学习笔记(三)TOraSession(4)
- day11-mysql中的mysql数据库不见了
- Python——eventlet.backdoor
- 自己写的jQuery颜色插件
- js中哈希表的几种用法总结