⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 where.cpp

📁 数值计算工具库,C语言编写的,可以直接调用.
💻 CPP
字号:
/*****************************************************************************
 *
 * where.cpp     Blitz++ Vector<T> example, illustrating where(X,Y,Z)
 *               expressions.
 *
 * $Id: where.cpp,v 1.1 1997/07/16 19:38:23 tveldhui Exp $
 *
 * $Log: where.cpp,v $
 * Revision 1.1  1997/07/16 19:38:23  tveldhui
 * Update: Alpha release 0.2 (Arrays)
 *
 */

#include <blitz/vector.h>
#include <blitz/vecwhere.h>

#ifdef BZ_NAMESPACES
using namespace blitz;
#endif

int main()
{
    Vector<int> x = Range(-3,+3);   // [ -3 -2 -1  0  1  2  3 ]

    // The where(X,Y,Z) function is similar to the X ? Y : Z operator.
    // If X is logical true, then Y is returned; otherwise, Z is
    // returned.

    Vector<int> y = where(abs(x) > 2, x+10, x-10);

    // The above statement is transformed into something resembling:
    //
    // for (unsigned i=0; i < 7; ++i)
    //     y[i] = (abs(x[i]) > 2) ? (x[i]+10) : (x[i]-10);
    //
    // The first expression (abs(x) > 2) can involve the usual
    // comparison and logical operators: < > <= >= == != && || 

    cout << x << endl
         << y << endl;

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -