a = pyublas.zeros((5,5), flavor=pyublas.SparseBuildMatrix, dtype=float)
#SparseBuildMatrix是稀疏矩阵类型
#将第5行(行号从0开始),第2个元素赋值为19
a[4,2] = 19
#将第一行赋值为4
a[1]=4
#将a全部赋值为1
a[:]=1
#从a中切片出一个小矩阵
a[:3,:3]
#对a进行乘法运算,加,减类似
a=a*a
#可以添加一个小的块状矩阵
b = numpy.random.randn(2,2)
a.add_block(2, 2, b)
#打印出所有非0元素的位置和值
for i in a.indices():print i,a
#a中非0元素的个数
print a.nnz
#对a中元素求和
print a.sum()
#array是什么意思???我没明白。。。也许array之后更快?
#更新,哦,我少看了一段:
"""
The SparseBuildMatrix flavor is designed for fastest possible assembly of sparse matrices, while the SparseExecuteMatrix flavor is made for the fastest possible matrix-vector product. There’s much more functionality here–don’t be afraid to peek into the source code.
"""