E022

orsci中subvector、span、dyn、conn函数和字符串表达式。subvect()生成子向量,view()是向量视图,形成引用。span()形成序列索引,dyn()是动态索引,conn()可用于多个索引组合。此外,字符串表达式经常使用:例如"1:10","1:5, 8, 12, 18:-1:8"

 

#include "stdafx.h"

#include "orsciJWVCL.h"
#include "orsciVM.h"
using namespace orsci;
using namespace orsci::vmt;


int main()
{
cout << " orsci: subvect()、span()、dyn()、conn()、strExp ... http://www.orsci.cn" << endl;
cout << endl;
vdouble x = "10:29"; //字符串表达式构造向量,也可构造索引。
cout << x << endl;

cout << "字符串表达式:\"1:5, 8, 12, 18:-1:8\"" << endl;
cout << vint("1:5, 8, 12, 18:-1:8") << endl;

vint index = "1:5, 8, 12, 18:-1:8"; //利用表达式生成向量或者索引。
cout << "x.subvect(\"1:5, 8, 12, 18:-1:8\")=" << endl;
cout << x.subvector(index) << endl;

cout << "span(...)常用于生成序列索引。span(1, 2, 8)=" << endl;
cout << span(1, 2, 8) << endl;

cout << "subvect(...)用于抽取子向量。x.subvector(span(1, 2, 8))=" << endl;
cout << x.subvector(span(1, 2, 8)) << endl;

cout << "dyn(...)构造动态数组" << endl;
cout << dyn(3, 1, 5, 6, 5) << endl;

cout << "subvect(...)用于抽取子向量。x.subvector(dyn(3, 1, 5, 2, 5))=" << endl;
cout << x.subvector(dyn(3, 1, 5, 2, 5)) << endl;

cout << "conn(...)将多个数组连接...conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5))=" << endl;
cout << conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5)) << endl;

cout << "x.subvector(conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5)))=" << endl;
cout << x.subvector(conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5))) << endl;

cout << "span(5, -1, 2) = " << endl;
cout << span(5, -1, 2) << endl;

cout << "conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5), span(5, -1, 2)) = " << endl;
cout << conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5), span(5, -1, 2)) << endl;

cout << "x.subvector(spanToTail(3)) = " << endl;
cout << x.subvector(spanToTail(3)) << endl;
cout << endl;

cout << "press any key to stop..." << endl;
char pp;
cin >> pp;
return 0;
}

输出

(一)运行结果

orsci: subvect()、span()、dyn()、conn()、strExp ... http://www.orsci.cn

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
字符串表达式:"1:5, 8, 12, 18:-1:8"
1 2 3 4 5 8 12 18 17 16 15 14 13 12 11 10 9 8
x.subvect("1:5, 8, 12, 18:-1:8")=
11 12 13 14 15 18 22 28 27 26 25 24 23 22 21 20 19 18
span(...)常用于生成序列索引。span(1, 2, 8)=
1 3 5 7
subvect(...)用于抽取子向量。x.subvector(span(1, 2, 8))=
11 13 15 17
dyn(...)构造动态数组
3 1 5 6 5
subvect(...)用于抽取子向量。x.subvector(dyn(3, 1, 5, 2, 5))=
13 11 15 12 15
conn(...)将多个数组连接...conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5))=
1 3 5 7 3 1 5 2 5
x.subvector(conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5)))=
11 13 15 17 13 11 15 12 15
span(5, -1, 2) =
5 4 3 2
conn(span(1, 2, 8), dyn(3, 1, 5, 2, 5), span(5, -1, 2)) =
1 3 5 7 3 1 5 2 5 5 4 3 2
x.subvector(spanToTail(3)) =
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

press any key to stop...

(二)说明:

(1)向量与矩阵中的索引至关重要,字符串表达式(如"1:5")、span(...)、dyn(...)和conn(...)常用于创建索引。

(2)关于向量与矩阵,请参看书籍:姜维. 《数据分析与数据挖掘》、《数据分析与数据挖掘建模与工具》

(6)orsci包支持向量和矩阵计算,可下载配套软件orsci应用。

书籍 姜维. 《数据分析与数据挖掘》、《数据分析与数据挖掘建模与工具》
软件 orsci开发包(C++语言、Delphi语言和C语言)。