Oct2py Documentation Release 4.3.0

Total Page:16

File Type:pdf, Size:1020Kb

Oct2py Documentation Release 4.3.0 Oct2Py Documentation Release 4.3.0 Oct2Py contributors May 02, 2019 CONTENTS 1 Features 3 2 API Reference 17 3 Installation 19 4 Examples 21 5 Type Conversions 23 6 Information 25 Python Module Index 27 i ii Oct2Py Documentation, Release 4.3.0 Oct2Py allows you to seamlessly call M-files and Octave functions from Python. It manages the Octave session for you, sharing data behind the scenes using MAT files. Usage is as simple as: >>> oc= oct2py.Oct2Py() >>> x= oc.zeros(3,3) >>> print(x, x.dtype) [[ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.]] float64 ... If you want to run legacy m-files, do not have MATLAB®, and do not fully trust a code translator, this is your library. CONTENTS 1 Oct2Py Documentation, Release 4.3.0 2 CONTENTS CHAPTER ONE FEATURES • Supports all Octave datatypes and most Python datatypes and Numpy dtypes. • Provides OctaveMagic for IPython, including inline plotting in notebooks. • Supports cell arrays and structs/struct arrays with arbitrary nesting. • Supports sparse matrices. • Builds methods on the fly linked to Octave commands (e.g. zeros above). • Thread-safety: each Oct2Py object uses an independent Octave session. • Can be used as a context manager. • Supports Unicode characters. • Supports logging of session commands. • Optional timeout command parameter to prevent runaway Octave sessions. 1.1 Installation 1.1.1 Library Installation You must have GNU Octave installed and in your PATH (see instructions below). The library is only known to work with Octave 4.0+. Additionally, you must have the Numpy and Scipy libraries for Python installed. The simplest way to get them is to use the Anaconda distribution. Once the dependencies have been installed, run: $ pip install oct2py If using conda, it is available on conda-forge: $ conda install -c conda-forge oct2py 1.1.2 GNU Octave Installation • On Linux platforms, try your package manager, or follow the instructions from Octave. You must also have gnuplot installed, and gnuplot-x11 or gnuplot-qt, if available. • On OSX, the recommended methods are listed on this wiki. 3 Oct2Py Documentation, Release 4.3.0 • On Windows, download the latest MinGW or .NET version. Cygwin is NOT supported. The MinGW version requires the 7zip program for installation. Make sure to install gnuplot if prompted. Finally, to add Octave to your path. You can do so from the Environmental Variables dialog for your version of Windows, or set from the command prompt: setx PATH"%PATH%;<path-to-octave-dir> Where the folder <path-to-octave-dir> has the file “octave.exe”. If you see the message: “WARNINGS: The data being saved is truncated to 1024 characters” It means your PATH variable is too long. You’ll have to manually trim in in the Windows Environmental Variables editor. • To test, open a command window (or terminal) and type: octave. If Octave starts, you should be good to go. • Alternatively, you can specify the path to your Octave executable by creating an OCTAVE_EXECUTABLE en- vironmental variable. 1.2 Demo Output of Oct2Py demo script, showing most of the features of the library. Note that the two plot commands will generate an interactive plot in the actual demo. To run interactively: >>> ######################### >>> # Oct2Py demo >>> ######################### >>> import numpy as np >>> from oct2py import Oct2Py >>> oc= Oct2Py() >>> # basic commands >>> print(oc.abs(-1)) 1 >>> print(oc.upper('xyz')) XYZ >>> # plotting >>> oc.plot([1,2,3],'-o','linewidth',2) Press Enter to continue... 4 Chapter 1. Features Oct2Py Documentation, Release 4.3.0 >>> oc.close() >>> xx= np.arange(-2 *np.pi,2 *np.pi, 0.2) >>> oc.surf(np.subtract.outer(np.sin(xx), np.cos(xx))) Press Enter to continue... 1.2. Demo 5 Oct2Py Documentation, Release 4.3.0 >>> oc.close() >>> # getting help >>> help(oc.svd) Help on function svd in module oct2py.session: svd(*args, **kwargs) `svd' is a function from the file c:\Program Files\Octave-3.6.2\lib\octave\3.6. ,!2\oct\i686-pc-mingw32\svd.oct -- Loadable Function: S = svd (A) -- Loadable Function: [U, S, V] = svd (A) -- Loadable Function: [U, S, V] = svd (A, ECON) Compute the singular value decomposition of A A = U*S*V' The function `svd' normally returns only the vector of singular values. When called with three return values, it computes U, S, and V. For example, svd (hilb (3)) (continues on next page) 6 Chapter 1. Features Oct2Py Documentation, Release 4.3.0 (continued from previous page) returns ans = 1.4083189 0.1223271 0.0026873 and [u, s, v] = svd (hilb (3)) returns u = -0.82704 0.54745 0.12766 -0.45986 -0.52829 -0.71375 -0.32330 -0.64901 0.68867 s = 1.40832 0.00000 0.00000 0.00000 0.12233 0.00000 0.00000 0.00000 0.00269 v = -0.82704 0.54745 0.12766 -0.45986 -0.52829 -0.71375 -0.32330 -0.64901 0.68867 If given a second argument, `svd' returns an economy-sized decomposition, eliminating the unnecessary rows or columns of U or V. See also: svd_driver, svds, eig Additional help for built-in functions and operators is available in the on-line version of the manual. Use the command `doc <topic>' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the [email protected] mailing list. >>> # single vs. multiple return values >>> print(oc.svd(np.array([[1,2], [1,3]]))) [[ 3.86432845] [ 0.25877718]] >>> U, S, V= oc.svd([[1,2], [1,3]], nout=3) >>> print(U, S, V) [[-0.57604844 -0.81741556] [-0.81741556 0.57604844]] [[ 3.86432845 0. ] (continues on next page) 1.2. Demo 7 Oct2Py Documentation, Release 4.3.0 (continued from previous page) [ 0. 0.25877718]] [[-0.36059668 -0.93272184] [-0.93272184 0.36059668]] >>> # low level constructs >>> oc.eval("y=ones(3,3)") >>> print(oc.pull("y")) [[ 1. 1. 1.] [ 1. 1. 1.] [ 1. 1. 1.]] >>> oc.eval("x=zeros(3,3)", verbose=True) >>> t= oc.eval('rand(1, 2)', verbose=True) >>> y= np.zeros((3,3)) >>> oc.push('y', y) >>> print(oc.pull('y')) [[ 0. 0. 0.] [ 0. 0. 0.] [ 0. 0. 0.]] >>> from oct2py import Struct >>> y= Struct() >>> y.b='spam' >>> y.c.d='eggs' >>> print(y.c['d']) eggs >>> print(y) {'c': {'d': 'eggs'}, 'b': 'spam'} >>> ######################### >>> # Demo Complete! >>> ######################### 1.3 Examples 1.3.1 OctaveMagic Oct2Py provides a plugin for IPython to bring Octave to the IPython prompt or the IPython Notebook. 1.3.2 M-File Examples M-files in the directory where oct2py was initialized, or those in the Octave path, can be called like any other Octave function. To explicitly add to the path, use: >>> from oct2py import octave >>> octave.addpath('/path/to/directory') to add the directory in which your m-file is located to Octave’s path. Roundtrip roundtrip.m function [x, class] = roundtrip(y) % returns the input variable and its class (continues on next page) 8 Chapter 1. Features Oct2Py Documentation, Release 4.3.0 (continued from previous page) x = y class = class(x) Python Session >>> from oct2py import octave >>> import numpy as np >>> x= np.array([[1,2], [3,4]], dtype=float) >>> out, oclass= octave.roundtrip(x) >>> import pprint >>> pprint.pprint([x, x.dtype, out, oclass, out.dtype]) [array([[ 1., 2.], [ 3., 4.]]), dtype('float64'), array([[ 1., 2.], [ 3., 4.]]), 'double', dtype('float64')] Test Datatypes test_datatypes.m function test= test_datatypes() % Test of returning a structure with multiple % nesting and multiple return types %%%%%%%%%%%%%%% % numeric types % integers test.num.int.int8= int8(-2^7); test.num.int.int16= int16(-2^15); test.num.int.int32= int32(-2^31); test.num.int.int64= int64(-2^63); test.num.int.uint8= uint8(2^8-1); test.num.int.uint16= uint16(2^16-1); test.num.int.uint32= uint32(2^32-1); test.num.int.uint64= uint64(2^64-1); %floats test.num.float32= single(pi); test.num.float64= double(pi); test.num.complex=3+1j; test.num.complex_matrix=(1+1j) * rand([22]) % misc test.num.inf= inf test.num.NaN= NaN test.num.matrix=[12;34] test.num.vector=[1234] test.num.column_vector=[1;2;3;4] test.num.matrix3d= rand([234]) (continues on next page) 1.3. Examples 9 Oct2Py Documentation, Release 4.3.0 (continued from previous page) test.num.matrix5d= rand(1,2,3,4,5) %%%%%%%%%%%%%%% % logical type test.logical=[10 20 30 40 50]> 30 %%%%%%%%%%%%%%% % string types test.string.basic='spam' test.string.char_array={'spam','eggs';'foo','bar'} test.string.cell_array={'spam','eggs'} %%%%%%%%%%%%%%% % struct types test.struct.array(1).name='Sharon' test.struct.array(1).age= 31 test.struct.array(2).name='Bill' test.struct.array(2).age= 42 %%%%%%%%%%%%%%% % cell array types test.cell.vector={'spam', 4.0,[123]} test.cell.matrix={'Bob', 40;'Pam', 41} Python Session >>> from oct2py import octave >>> out= octave.test_dataypes() >>> import pprint >>> pprint.pprint(out) {u'cell': {u'matrix': [['Bob', 'Pam'], [40.0, 41.0]], u'vector': ['spam', 4.0, array([[ 1., 2., 3.]])]}, u'logical': array([[0, 0, 0, 1, 1]]), u'num': {u'NaN': nan, u'column_vector': array([[ 1.], [ 2.], [ 3.], [ 4.]]), u'complex': (3+1j), u'complex_matrix': array([[ 0.29801132+0.29801132j, 0.25385592+0. ,!25385592j], [ 0.36628765+0.36628765j, 0.17222843+0.17222843j]]), u'float32': 3.1415927, u'float64': 3.1415926535897931, u'inf': inf, u'int': {u'int16': -32768, u'int32': -2147483648, u'int64': -9223372036854775808, u'int8': -128, u'uint16': 65535, u'uint32': 4294967295, u'uint64': 18446744073709551615, u'uint8': 255}, u'matrix': array([[ 1., 2.], (continues on next page) 10 Chapter 1. Features Oct2Py Documentation, Release 4.3.0 (continued from previous page) [ 3., 4.]]), u'matrix3d': array([[[ 0.37748504, 0.42576504, 0.33770276, 0.28353423], [ 0.07772849, 0.79317342, 0.35633704, 0.84392906], [ 0.27743843, 0.58173155,
Recommended publications
  • Alternatives to Python: Julia
    Crossing Language Barriers with , SciPy, and thon Steven G. Johnson MIT Applied Mathemacs Where I’m coming from… [ google “Steven Johnson MIT” ] Computaonal soPware you may know… … mainly C/C++ libraries & soPware … Nanophotonics … oPen with Python interfaces … (& Matlab & Scheme & …) jdj.mit.edu/nlopt www.w.org jdj.mit.edu/meep erf(z) (and erfc, erfi, …) in SciPy 0.12+ & other EM simulators… jdj.mit.edu/book Confession: I’ve used Python’s internal C API more than I’ve coded in Python… A new programming language? Viral Shah Jeff Bezanson Alan Edelman julialang.org Stefan Karpinski [begun 2009, “0.1” in 2013, ~20k commits] [ 17+ developers with 100+ commits ] [ usual fate of all First reacBon: You’re doomed. new languages ] … subsequently: … probably doomed … sll might be doomed but, in the meanBme, I’m having fun with it… … and it solves a real problem with technical compuBng in high-level languages. The “Two-Language” Problem Want a high-level language that you can work with interacBvely = easy development, prototyping, exploraon ⇒ dynamically typed language Plenty to choose from: Python, Matlab / Octave, R, Scilab, … (& some of us even like Scheme / Guile) Historically, can’t write performance-criBcal code (“inner loops”) in these languages… have to switch to C/Fortran/… (stac). [ e.g. SciPy git master is ~70% C/C++/Fortran] Workable, but Python → Python+C = a huge jump in complexity. Just vectorize your code? = rely on mature external libraries, operang on large blocks of data, for performance-criBcal code Good advice! But… • Someone has to write those libraries. • Eventually that person may be you.
    [Show full text]
  • Data Visualization in Python
    Data visualization in python Day 2 A variety of packages and philosophies • (today) matplotlib: http://matplotlib.org/ – Gallery: http://matplotlib.org/gallery.html – Frequently used commands: http://matplotlib.org/api/pyplot_summary.html • Seaborn: http://stanford.edu/~mwaskom/software/seaborn/ • ggplot: – R version: http://docs.ggplot2.org/current/ – Python port: http://ggplot.yhathq.com/ • Bokeh (live plots in your browser) – http://bokeh.pydata.org/en/latest/ Biocomputing Bootcamp 2017 Matplotlib • Gallery: http://matplotlib.org/gallery.html • Top commands: http://matplotlib.org/api/pyplot_summary.html • Provides "pylab" API, a mimic of matlab • Many different graph types and options, some obscure Biocomputing Bootcamp 2017 Matplotlib • Resulting plots represented by python objects, from entire figure down to individual points/lines. • Large API allows any aspect to be tweaked • Lengthy coding sometimes required to make a plot "just so" Biocomputing Bootcamp 2017 Seaborn • https://stanford.edu/~mwaskom/software/seaborn/ • Implements more complex plot types – Joint points, clustergrams, fitted linear models • Uses matplotlib "under the hood" Biocomputing Bootcamp 2017 Others • ggplot: – (Original) R version: http://docs.ggplot2.org/current/ – A recent python port: http://ggplot.yhathq.com/ – Elegant syntax for compactly specifying plots – but, they can be hard to tweak – We'll discuss this on the R side tomorrow, both the basics of both work similarly. • Bokeh – Live, clickable plots in your browser! – http://bokeh.pydata.org/en/latest/
    [Show full text]
  • Ipython: a System for Interactive Scientific
    P YTHON: B ATTERIES I NCLUDED IPython: A System for Interactive Scientific Computing Python offers basic facilities for interactive work and a comprehensive library on top of which more sophisticated systems can be built. The IPython project provides an enhanced interactive environment that includes, among other features, support for data visualization and facilities for distributed and parallel computation. he backbone of scientific computing is All these systems offer an interactive command mostly a collection of high-perfor- line in which code can be run immediately, without mance code written in Fortran, C, and having to go through the traditional edit/com- C++ that typically runs in batch mode pile/execute cycle. This flexible style matches well onT large systems, clusters, and supercomputers. the spirit of computing in a scientific context, in However, over the past decade, high-level environ- which determining what computations must be ments that integrate easy-to-use interpreted lan- performed next often requires significant work. An guages, comprehensive numerical libraries, and interactive environment lets scientists look at data, visualization facilities have become extremely popu- test new ideas, combine algorithmic approaches, lar in this field. As hardware becomes faster, the crit- and evaluate their outcome directly. This process ical bottleneck in scientific computing isn’t always the might lead to a final result, or it might clarify how computer’s processing time; the scientist’s time is also they need to build a more static, large-scale pro- a consideration. For this reason, systems that allow duction code. rapid algorithmic exploration, data analysis, and vi- As this article shows, Python (www.python.org) sualization have become a staple of daily scientific is an excellent tool for such a workflow.1 The work.
    [Show full text]
  • Writing Mathematical Expressions with Latex
    APPENDIX A Writing Mathematical Expressions with LaTeX LaTeX is extensively used in Python. In this appendix there are many examples that can be useful to represent LaTeX expressions inside Python implementations. This same information can be found at the link http://matplotlib.org/users/mathtext.html. With matplotlib You can enter the LaTeX expression directly as an argument of various functions that can accept it. For example, the title() function that draws a chart title. import matplotlib.pyplot as plt %matplotlib inline plt.title(r'$\alpha > \beta$') With IPython Notebook in a Markdown Cell You can enter the LaTeX expression between two '$$'. $$c = \sqrt{a^2 + b^2}$$ c= a+22b 537 © Fabio Nelli 2018 F. Nelli, Python Data Analytics, https://doi.org/10.1007/978-1-4842-3913-1 APPENDIX A WRITING MaTHEmaTICaL EXPRESSIONS wITH LaTEX With IPython Notebook in a Python 2 Cell You can enter the LaTeX expression within the Math() function. from IPython.display import display, Math, Latex display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')) Subscripts and Superscripts To make subscripts and superscripts, use the ‘_’ and ‘^’ symbols: r'$\alpha_i > \beta_i$' abii> This could be very useful when you have to write summations: r'$\sum_{i=0}^\infty x_i$' ¥ åxi i=0 Fractions, Binomials, and Stacked Numbers Fractions, binomials, and stacked numbers can be created with the \frac{}{}, \binom{}{}, and \stackrel{}{} commands, respectively: r'$\frac{3}{4} \binom{3}{4} \stackrel{3}{4}$' 3 3 æ3 ö4 ç ÷ 4 è 4ø Fractions can be arbitrarily nested: 1 5 - x 4 538 APPENDIX A WRITING MaTHEmaTICaL EXPRESSIONS wITH LaTEX Note that special care needs to be taken to place parentheses and brackets around fractions.
    [Show full text]
  • ARM Code Development in Windows
    ARM Code Development in Windows By: Ali Nuhi This guide will describe how to develop code to be run on an embedded Linux system using an ARM processor (specifically the OMAP3530). Environment The Cygwin bash shell will be the environment used for code development. Download it from the below link. http://cygwin.com/install.html READ THE SITE. Download setup.exe and choose the packages you want to install. Some helpful packages to download are: -gcc4-core,g++ etc. (for c and c++ compiling of normal programs) -git core files and completion (version control system) -wget (utility to download files from the internet via HTTP and FTP) -VIM (text editor) -Xemacs (another text editor, better than vim) -nano (simple command line text editor) If you still use windows notepad for writing code please atleast upgrade to notepad++. Toolchain We will be compiling and creating files using CodeSourcery g++ lite toolchains. This is a modified version of GCC which will create files specifically for ARM target systems. Download this at: http://www.codesourcery.com/sgpp/lite/arm/portal/release1803 Download the Windows installer and execute. You can let it install as is unless you have some other install scheme on your computer. I highly recommend reading the getting started pdf that comes with CodeSourcery. Once it’s fully installed open up Cygwin and execute the below lines. $ export CYGPATH=cygpath $ export CYGPATH=c:/cygwin/bin/cygpath If you installed Cygwin to another directory then you must edit the second line. To use the compiler type the following and hit tab twice to see all of the possible options you have.
    [Show full text]
  • Cygwin User's Guide
    Cygwin User’s Guide Cygwin User’s Guide ii Copyright © Cygwin authors Permission is granted to make and distribute verbatim copies of this documentation provided the copyright notice and this per- mission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this documentation under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this documentation into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. Cygwin User’s Guide iii Contents 1 Cygwin Overview 1 1.1 What is it? . .1 1.2 Quick Start Guide for those more experienced with Windows . .1 1.3 Quick Start Guide for those more experienced with UNIX . .1 1.4 Are the Cygwin tools free software? . .2 1.5 A brief history of the Cygwin project . .2 1.6 Highlights of Cygwin Functionality . .3 1.6.1 Introduction . .3 1.6.2 Permissions and Security . .3 1.6.3 File Access . .3 1.6.4 Text Mode vs. Binary Mode . .4 1.6.5 ANSI C Library . .4 1.6.6 Process Creation . .5 1.6.6.1 Problems with process creation . .5 1.6.7 Signals . .6 1.6.8 Sockets . .6 1.6.9 Select . .7 1.7 What’s new and what changed in Cygwin . .7 1.7.1 What’s new and what changed in 3.2 .
    [Show full text]
  • Ipython Documentation Release 0.10.2
    IPython Documentation Release 0.10.2 The IPython Development Team April 09, 2011 CONTENTS 1 Introduction 1 1.1 Overview............................................1 1.2 Enhanced interactive Python shell...............................1 1.3 Interactive parallel computing.................................3 2 Installation 5 2.1 Overview............................................5 2.2 Quickstart...........................................5 2.3 Installing IPython itself....................................6 2.4 Basic optional dependencies..................................7 2.5 Dependencies for IPython.kernel (parallel computing)....................8 2.6 Dependencies for IPython.frontend (the IPython GUI).................... 10 3 Using IPython for interactive work 11 3.1 Quick IPython tutorial..................................... 11 3.2 IPython reference........................................ 17 3.3 IPython as a system shell.................................... 42 3.4 IPython extension API..................................... 47 4 Using IPython for parallel computing 53 4.1 Overview and getting started.................................. 53 4.2 Starting the IPython controller and engines.......................... 57 4.3 IPython’s multiengine interface................................ 64 4.4 The IPython task interface................................... 78 4.5 Using MPI with IPython.................................... 80 4.6 Security details of IPython................................... 83 4.7 IPython/Vision Beam Pattern Demo.............................
    [Show full text]
  • Easybuild Documentation Release 20210907.0
    EasyBuild Documentation Release 20210907.0 Ghent University Tue, 07 Sep 2021 08:55:41 Contents 1 What is EasyBuild? 3 2 Concepts and terminology 5 2.1 EasyBuild framework..........................................5 2.2 Easyblocks................................................6 2.3 Toolchains................................................7 2.3.1 system toolchain.......................................7 2.3.2 dummy toolchain (DEPRECATED) ..............................7 2.3.3 Common toolchains.......................................7 2.4 Easyconfig files..............................................7 2.5 Extensions................................................8 3 Typical workflow example: building and installing WRF9 3.1 Searching for available easyconfigs files.................................9 3.2 Getting an overview of planned installations.............................. 10 3.3 Installing a software stack........................................ 11 4 Getting started 13 4.1 Installing EasyBuild........................................... 13 4.1.1 Requirements.......................................... 14 4.1.2 Using pip to Install EasyBuild................................. 14 4.1.3 Installing EasyBuild with EasyBuild.............................. 17 4.1.4 Dependencies.......................................... 19 4.1.5 Sources............................................. 21 4.1.6 In case of installation issues. .................................. 22 4.2 Configuring EasyBuild.......................................... 22 4.2.1 Supported configuration
    [Show full text]
  • Intro to Jupyter Notebook
    Evan Williamson University of Idaho Library 2016­03­02 Introducing Jupyter Notebook for Python and R Three questions: http://goo.gl/forms/uYRvebcJkD ​ Try Jupyter https://try.jupyter.org/ Install Jupyter ● Get Python (suggested: Anaconda, Py3, 64­bit, https://www.continuum.io/downloads ) ​ ​ ● Manually install (if necessary), http://jupyter.readthedocs.org/en/latest/install.html ​ pip3 install jupyter Install R for Jupyter ● Get R, https://cran.cnr.berkeley.edu/ ​ (suggested: RStudio, https://www.rstudio.com/products/RStudio/#Desktop ) ​ ​ ● Open R console and follow: http://irkernel.github.io/installation/ ​ Start a Notebook ● Open terminal/command prompt jupyter notebook ● Notebook will open at http://127.0.0.1:8888 ​ ● Exit by closing the browser, then typing Ctrl+C in the terminal window Create Slides ● Open terminal/command prompt jupyter nbconvert slideshow.ipynb --to slides --post serve ● Note: “­­post serve” locally serves the file so you can give a presentation in your browser. If you only want to convert, leave this option off. The resulting HTML file must be served to render correctly. Slides use Reveal.js, http://lab.hakim.se/reveal­js/ ​ Reference ● Jupyter docs, http://jupyter.readthedocs.org/en/latest/index.html ​ ● IPython docs, http://ipython.readthedocs.org/en/stable/index.html ​ ● List of kernels, https://github.com/ipython/ipython/wiki/IPython­kernels­for­other­languages ● A gallery of interesting IPython Notebooks, https://github.com/ipython/ipython/wiki/A­gallery­of­interesting­IPython­Notebooks ● Markdown basics,
    [Show full text]
  • CS102: Introduction to Python the Goal of This Topic Is to Provide a Brief
    CS102: Introduction to Python The goal of this topic is to provide a brief introduction to Python to give you a feel for a language other than C. In many ways, Python is very different from C. It is generally considered to be a scripting language, although the distinction between scripting languages and other programming languages is not really clear-cut. Scripting languages tend to be interpreted rather than compiled; they tend not to require declarations of variables (the interpreter figures out types based on context); they tend to hide memory management from the programmer; they tend to support regular expressions; etc. In terms of usage, scripting languages tend to be useful for writing short programs quickly when you don't care too much about efficiency. Other languages that are typically considered to be scripting languages include Perl, Awk, and JavaScript. Python supports several styles of programming, including (but not limited to) procedural programming (like C and C++), object-oriented programming (like C++ and Java), and functional programming (like Lisp). Note that it is not a mistake to include C++ in two categories, just as it is not a mistake to include Python in all three of these categories. The first version of Python was released in the late 1980s. Python 2.0 was released in 2000, and various improvements have been made in the Python 2.x chain of releases since that time. Python 3.0 was released in 2008, and again, various improvements have been made in the Python 3.0 chain of releases. Unfortunately, the Python 3 interpreter is not backwards compatible with Python 2, and there seems to be debate as to which is the better version of Python to learn.
    [Show full text]
  • Numpy for MATLAB Users – Mathesaurus
    NumPy for MATLAB users Help MATLAB/Octave Python Description doc help() Browse help interactively help -i % browse with Info help help or doc doc help Help on using help help plot help(plot) or ?plot Help for a function help splines or doc splines help(pylab) Help for a toolbox/library package demo Demonstration examples Searching available documentation MATLAB/Octave Python Description lookfor plot Search help files help help(); modules [Numeric] List available packages which plot help(plot) Locate functions Using interactively MATLAB/Octave Python Description octave -q ipython -pylab Start session TAB or M-? TAB Auto completion foo(.m) execfile('foo.py') or run foo.py Run code from file history hist -n Command history diary on [..] diary off Save command history exit or quit CTRL-D End session CTRL-Z # windows sys.exit() Operators MATLAB/Octave Python Description help - Help on operator syntax Arithmetic operators MATLAB/Octave Python Description a=1; b=2; a=1; b=1 Assignment; defining a number a + b a + b or add(a,b) Addition a - b a - b or subtract(a,b) Subtraction a * b a * b or multiply(a,b) Multiplication a / b a / b or divide(a,b) Division a .^ b a ** b Power, $a^b$ power(a,b) pow(a,b) rem(a,b) a % b Remainder remainder(a,b) fmod(a,b) a+=1 a+=b or add(a,b,a) In place operation to save array creation overhead factorial(a) Factorial, $n!$ Relational operators MATLAB/Octave Python Description a == b a == b or equal(a,b) Equal a < b a < b or less(a,b) Less than a > b a > b or greater(a,b) Greater than a <= b a <= b or less_equal(a,b)
    [Show full text]
  • Sage Tutorial (Pdf)
    Sage Tutorial Release 9.4 The Sage Development Team Aug 24, 2021 CONTENTS 1 Introduction 3 1.1 Installation................................................4 1.2 Ways to Use Sage.............................................4 1.3 Longterm Goals for Sage.........................................5 2 A Guided Tour 7 2.1 Assignment, Equality, and Arithmetic..................................7 2.2 Getting Help...............................................9 2.3 Functions, Indentation, and Counting.................................. 10 2.4 Basic Algebra and Calculus....................................... 14 2.5 Plotting.................................................. 20 2.6 Some Common Issues with Functions.................................. 23 2.7 Basic Rings................................................ 26 2.8 Linear Algebra.............................................. 28 2.9 Polynomials............................................... 32 2.10 Parents, Conversion and Coercion.................................... 36 2.11 Finite Groups, Abelian Groups...................................... 42 2.12 Number Theory............................................. 43 2.13 Some More Advanced Mathematics................................... 46 3 The Interactive Shell 55 3.1 Your Sage Session............................................ 55 3.2 Logging Input and Output........................................ 57 3.3 Paste Ignores Prompts.......................................... 58 3.4 Timing Commands............................................ 58 3.5 Other IPython
    [Show full text]