background preloader

Numpy

Facebook Twitter

1.3.1. The Numpy array object — Scipy lecture notes. 1.3.1.3.

1.3.1. The Numpy array object — Scipy lecture notes

Basic data types You may have noticed that, in some instances, array elements are displayed with a trailing dot (e.g. 2. vs 2). This is due to a difference in the data-type used: >>> a = np.array([1, 2, 3])>>> a.dtypedtype('int64') >>> b = np.array([1., 2., 3.]) >>> b.dtypedtype('float64') Tip Different data-types allow us to store data more compactly in memory, but most of the time we simply work with floating point numbers. You can explicitly specify which data-type you want: >>> c = np.array([1, 2, 3], dtype=float)>>> c.dtypedtype('float64') The default data type is floating point: >>> a = np.ones((3, 3))>>> a.dtypedtype('float64') There are also other types: 1.3.1.4.

Now that we have our first data arrays, we are going to visualize them. Start by launching IPython in pylab mode. Or the notebook: $ ipython notebook --pylab=inline Alternatively, if IPython has already been started: Or, from the notebook: Matplotlib is a 2D plotting package. >>> import matplotlib.pyplot as plt # the tidy way. Linear Algebra (scipy.linalg) When SciPy is built using the optimized ATLAS LAPACK and BLAS libraries, it has very fast linear algebra capabilities.

Linear Algebra (scipy.linalg)

If you dig deep enough, all of the raw lapack and blas libraries are available for your use for even more speed. In this section, some easier-to-use interfaces to these routines are described. All of these linear algebra routines expect an object that can be converted into a 2-dimensional array. The output of these routines is also a two-dimensional array. Python - Stacked bar chart with differently ordered colors using matplotlib. Numpy.putmask — NumPy v1.5.dev8106 Manual (DRAFT) Tentative NumPy Tutorial - Please do not hesitate to click the button.

Tentative NumPy Tutorial -

You will need to create a User Account first. Before reading this tutorial you should know a bit of Python. If you would like to refresh your memory, take a look at the Python tutorial . If you wish to work the examples in this tutorial, you must also have some software installed on your computer. Minimally: Python NumPy These you may find useful: ipython is an enhanced interactive Python shell which is very convenient for exploring NumPy's features matplotlib will enable you to plot graphics SciPy provides a lot of scientific routines that work on top of NumPy NumPy's main object is the homogeneous multidimensional array. For example, the coordinates of a point in 3D space [1, 2, 1] is an array of rank 1, because it has one axis.

Numpy's array class is called ndarray . Ndarray.ndim the number of axes (dimensions) of the array. Ndarray.shape the dimensions of the array. Ndarray.size the total number of elements of the array. NumPy for Numeric/numarray users – Mathesaurus. NumPy for MATLAB users – Mathesaurus. Help Searching available documentation Using interactively Operators Arithmetic operators Relational operators Logical operators root and logarithm Round off Mathematical constants Missing values; IEEE-754 floating point status flags Complex numbers Trigonometry Generate random numbers Vectors Sequences Concatenation (vectors) Repeating Miss those elements out Maximum and minimum Vector multiplication Matrices Concatenation (matrices); rbind and cbind Array creation Reshape and flatten matrices Shared data (slicing) Indexing and accessing elements (Python: slicing) Assignment Transpose and inverse Sum Sorting Matrix manipulation Equivalents to "size" Matrix- and elementwise- multiplication Find; conditional indexing Multi-way arrays File input and output Plotting Basic x-y plots Axes and titles Log plots Filled plots and bar plots Functions Polar plots Histogram plots 3d data Contour and image plots Perspective plots of surfaces over the x-y plane Scatter (cloud) plots Save plot to a graphics file Data analysis.

NumPy for MATLAB users – Mathesaurus

Scientific Scripting with Python for Computational Immunology — python v0.1 documentation.