Mathematica 输入与输出
基本输出
Mathematica的基本输出命令是Print,具体用法为:
Print[expr]
输出 expr.
例如:
Print["Hello world"]
Hello world
Print[2^10]
1024
Print命令也可以一次输出多项内容(用逗号,隔开),输出时每项内容之间无间隔:
Print["Hello world", 2^10]
Hello world1024
Mathematica的基本输出命令是Print,具体用法为:
Print[expr]
输出 expr.
例如:
Print["Hello world"]
Hello world
Print[2^10]
1024
Print命令也可以一次输出多项内容(用逗号,隔开),输出时每项内容之间无间隔:
Print["Hello world", 2^10]
Hello world1024
本文主要记录Mathematica笔记本(notebook)使用过程中的一些小细节(Tips)。
所有包含在(*和*)之间的内容为注释内容,都会被Mathematica内核忽略。
所有的Mathematica命令都是以大写字母开头的,Mathematica区分字母大小写。因此,为了避免冲突,所有的用户定义符号都应当用小写字母开头。
Mathematica中用方括号[]表示函数参数。例如:
cx_Freeze是一个打包Python应用的工具,通过cx_Freeze,可以制作Windows平台、MacOS平台、以及Linux平台的二进制可执行程序,使得Python应用能够在没有安装Python环境的机器上运行。
同很多Python的第三方库类似,cx_Freeze也可以通过如下命令安装:
pip install cx_Freeze
或者从官网下载安装包,解压后,切换目录至解压后的根目录,运行命令
python setup.py install
即可。
pyc文件是Python的字节码(byte code)文件,是一种二进制文件。pyc文件跨平台,由python的虚拟机加载执行。pyc文件与Python的版本有关,不同版本的Python编译出的pyc文件不同。
pyo文件是优化(optimize)后的字节码文件。
可以在命令行执行以下命令来将Python源码文件编译成pyc文件:
python -m py_compile $filename
其中,$filename是要编译的Python源码文件名。
也可以编写一下脚本来将Python源码文件编译成pyc文件:
sleep这一功能在不同的编译器中实现不同,API也有差别。
GCC编译器中,sleep定义在<unistd.h>中。函数原型:
/* The sleep() function is, perhaps, the most commonly used of all the
* process/thread suspension APIs; it provides support for specification
* of suspension periods ranging from 1 second to ~136 years. (However,
* POSIX recommends limiting the maximum period to 65535 seconds, to
* maintain portability to platforms with only 16-bit ints).
*/
unsigned _cdecl __MINGW_NOTHROW sleep( unsigned );
注意,在GCC的实现中,sleep的单位为秒(second)。
grep -w "word"
grep '\<word'
grep 'word\>'
GHC(Glasgow Haskell Compiler): an interactive and batch compilation system for the Haskell 98 language.
GHC has two main components: an interactive Haskell interpreter (also known as GHCi), and a batch compiler, described throughout. In fact, GHC consists of a single program which is just run with different options to provide either the interactive or the batch system.
GHCi是一个GHC的交互式环境,在GHCi中可以交互式地求得对Haskell表达式的值,Haskell程序也可以在GHCi中被解释。GCHi还包含了一个交互式的Haskell调试器。
函数指针是C语言的灵魂之一,基于C语言实现的面向对象,底层都以函数指针为基础。
C语言中,可以通过以下方式定义函数指针:
type (*fn)(args)
其中,fn为指针变量名,type为指针所指向的函数的返回值类型,args为指针所指向的函数的参数列表。可以通过&运算符对函数指针赋值,通过(*fn)()的方式调用。举例:
回调函数是指一个通过函数指针调用的函数。回掉函数不是由该函数的实现方法直接调用,而是在特定时间或条件发生时由另一方调用的,用于对该事件或条件进行响应。
C和C++中,可以通过函数指针的方式实现回调函数。如下例:
Decorator, 装饰器。Decorator的用途在于允许在函数和类中嵌入或者修改代码。
staticmethod(function)
这将返回一个function的静态方法。把类的一个方法的声明为静态方法,具体用法如下:
class C:
@staticmethod
def f(arg1, arg2, ...): ...
或者
class C:
def f(arg1, arg2, ...): ...
f = staticmethod(f)