用Armadillo功能替换“稀疏”
Replace `sparse.eye` with an armadillo function
我有一个python脚本,我想使用armadillo在C 中重写。在Python中,我有一行
matrix = 1/(12*h)*(sparse.eye(num_points, k = -2, dtype=np.complex).toarray() * 1 + sparse.eye(num_points, k = -1, dtype=np.complex).toarray() * -8 + sparse.eye(num_points, k = 1, dtype=np.complex).toarray() * 8 + sparse.eye(num_points, k = 2, dtype=np.complex).toarray() * -1)
生成我一个矩阵,其中所有值除了五个主角符为零。不幸的是,我在armadillo中找不到类似的功能,目前我能看到的最大的方式是创建一个ones()
-matrix,然后用.diag()
设置对角线,然后将其余的零。有一个更简单的方法吗?
以下代码应具有等效功能:
// sparse matrices have all values as zero at initialization
sp_mat X(10,10);
X.diag(-2).fill( 1);
X.diag(-1).fill(-8);
X.diag(+1).fill( 8);
X.diag(+2).fill(-1);
X *= 1.0 / (12*h); // the .0 in 1.0 tells the compiler to use the double type
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- C++中高效的大型稀疏块压缩线性方程
- 如何用转义符替换字符串中的所有特殊字符
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 如何在cuSparse中得到稀疏矩阵的对角线
- 在一个读写器队列中,我可以用volatile替换原子吗
- 用符号版本替换对函数的所有调用
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 替换基于地图的所有引用
- 按平均值替换数组中的元素
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 初始化 std::vector 替换为单大括号而不是双大括号
- 特征稀疏向量:求最大系数
- 删除/替换C++字符串中的多字符 (ÿû)
- 将 malloc 替换为数组
- 如何替换此示例代码片段中已弃用的handler_type_t或 boost::asio::handler_type?
- 如何在C++中用'\'替换''来处理转义序列?
- 替换密码:哪一个?
- 用Armadillo功能替换“稀疏”