[PDF] [PDF] NumPy Reference - Numpy and Scipy Documentation

18 oct 2015 · Mathematical functions with automatic domain (numpy emath) Warning: In place operations will perform the calculation using the precision decided by It has certain special operators, such as * (matrix multiplication) and



Previous PDF Next PDF





[PDF] 3 Matrix Algebra and Applications - Mathematical Sciences : UTEP

Chapter 3 Matrix Algebra and Applications 3 2 Matrix Multiplication Suppose we buy 2 CDs at $3 each and 4 Zip disks at $5 each We calculate our total cost



[PDF] 4048_y18_sy Maths O Level for 2018 - SEAB

An approved calculator may be used in both Paper 1 and Paper 2 multiplication and division of simple algebraic fractions such as:



[PDF] Cours de mathématiques M22 Algèbre linéaire

3 fév 2014 · Multiplication de matrices Inverse d'une matrice : systèmes linéaires et matrices élémentaires 29 6 FR exo7 emath 2 720 58 This will involve using a calculator or a table of trigonometric functions



[PDF] MATHEMATICS SYLLABUSES

9 4 problems involving addition, subtraction and multiplication of matrices calculation of the standard deviation for a set of data (grouped and ungrouped)



[PDF] NumPy Reference - Numpy and Scipy Documentation

18 oct 2015 · Mathematical functions with automatic domain (numpy emath) Warning: In place operations will perform the calculation using the precision decided by It has certain special operators, such as * (matrix multiplication) and



[PDF] NumPy Reference - Numpy and Scipy Documentation

15 mai 2011 · 3 25 Mathematical functions with automatic domain (numpy emath) For 2-D arrays it is equivalent to matrix multiplication, and for 1-D arrays to inner product of vectors By default, calculate the product of all elements:



[PDF] Water ninja trolling motor - Squarespace

rational expressions free algebra equation solver download Mortgages Graduate how matrix eBooks permutation and the combination of how to use the ti 83 Emath ks3 paper 1, math expressions in third class, how to graph decimal using 



[PDF] Gaussian Elimination and Back Substitution

Multiplying both sides of an equation by a scalar By working with the augmented matrix instead of the original system, there is no need to continually

[PDF] matrix multiplication calculator online

[PDF] matrix multiplication calculator with steps

[PDF] matrix multiplication calculator with variables

[PDF] matrix multiplication calculator wolfram

[PDF] matrix multiplication example

[PDF] matrix multiplication properties

[PDF] matrix operations

[PDF] matrix power

[PDF] matrix representation of graphs

[PDF] matrix row reduction

[PDF] matrix rref calculator wolfram

[PDF] matrix simultaneous equation calculator

[PDF] matrix solver

[PDF] matrix ti 89

[PDF] matrix vector multiplication c++

NumPy Reference

Release 1.9.2

Written by the NumPy community

October 18, 2015

CONTENTS

1 Array objects3

1.1 The N-dimensional array (ndarray). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.2 Scalars

74

1.3 Data type objects (dtype). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

1.4 Indexing

105

1.5 Iterating Over Arrays

112

1.6 Standard array subclasses

124

1.7 Masked arrays

243

1.8 The Array Interface

432

1.9 Datetimes and Timedeltas

437

2 Universal functions (ufunc)445

2.1 Broadcasting

445

2.2 Output type determination

446

2.3 Use of internal buffers

446

2.4 Error handling

446

2.5 Casting Rules

449

2.6 Overriding Ufunc behavior

451

2.7ufunc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .451

2.8 Available ufuncs

461

3 Routines465

3.1 Array creation routines

465

3.2 Array manipulation routines

501

3.3 Binary operations

542

3.4 String operations

550

3.5 C-Types Foreign Function Interface (numpy.ctypeslib). . . . . . . . . . . . . . . . . . . . . . 595

3.6 Datetime Support Functions

596

3.7 Data type routines

601

3.8 Optionally Scipy-accelerated routines (numpy.dual). . . . . . . . . . . . . . . . . . . . . . . . . 620

3.9 Mathematical functions with automatic domain (numpy.emath). . . . . . . . . . . . . . . . . . . 621

3.10 Floating point error handling

621

3.11 Discrete Fourier Transform (numpy.fft). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628

3.12 Financial functions

650

3.13 Functional programming

660

3.14 Numpy-specific help functions

666

3.15 Indexing routines

668

3.16 Input and output

701

3.17 Linear algebra (numpy.linalg). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725

3.18 Logic functions

759

3.19 Masked array operations

776 i

3.20 Mathematical functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901

3.21 Matrix library (numpy.matlib). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 967

3.22 Miscellaneous routines

973

3.23 Padding Arrays

974

3.24 Polynomials

977

3.25 Random sampling (numpy.random). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1154

3.26 Set routines

1251

3.27 Sorting, searching, and counting

1255

3.28 Statistics

1271

3.29 Test Support (numpy.testing). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1300

3.30 Window functions

1313

4 Packaging (numpy.distutils)1321

4.1 Modules innumpy.distutils. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1321

4.2 Building Installable C libraries

1332

4.3 Conversion of.srcfiles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1333

5 Numpy C-API1335

5.1 Python Types and C-Structures

1335

5.2 System configuration

1349

5.3 Data Type API

1351

5.4 Array API

1356

5.5 Array Iterator API

1395

5.6 UFunc API

1412

5.7 Generalized Universal Function API

1418

5.8 Numpy core libraries

1420

5.9 C API Deprecations

1426

6 Numpy internals1427

6.1 Numpy C Code Explanations

1427

6.2 Internal organization of numpy arrays

1434

6.3 Multidimensional Array Indexing Order Issues

1435

7 Numpy and SWIG1437

7.1 Numpy.i: a SWIG Interface File for NumPy

1437

7.2 Testing the numpy.i Typemaps

1452

8 Acknowledgements1455

Bibliography1457

Index1465ii

NumPy Reference, Release 1.9.2

Release

1.9 Date

October 18, 2015

This reference manual details functions, modules, and objects included in Numpy, describing what they are and what

they do. For learning how to use NumPy, see alsouser.CONTENTS1

NumPy Reference, Release 1.9.2

2CONTENTS

CHAPTER

ONEARRAY OBJECTS

NumPy provides an N-dimensional array type, thendarray, which describes a collection of "items" of the same type.

The items can beindexedusing for example N integers.

All ndarrays arehomogenous: every item takes up the same size block of memory, and all blocks are interpreted in

exactly the same way. How each item in the array is to be interpreted is specified by a separatedata-type object, one

of which is associated with every array. In addition to basic types (integers, floats,etc.), the data type objects can also

represent data structures.

An item extracted from an array,e.g., by indexing, is represented by a Python object whose type is one of thearray

scalar typesbuilt in Numpy. The array scalars allow easy manipulation of also more complicated arrangements of

data.Figure 1.1:FigureConceptual diagram showing the relationship between the three fundamental objects used to de-

scribe the data in an array: 1) the ndarray itself, 2) the data-type object that describes the layout of a single fixed-size

element of the array, 3) the array-scalar Python object that is returned when a single element of the array is accessed.

1.1

The N-dimensional arra y( ndarray)

Anndarrayis a (usually fixed-size) multidimensional container of items of the same type and size. The number

of dimensions and items in an array is defined by itsshape, which is atupleofNpositive integers that specify

the sizes of each dimension. The type of items in the array is specified by a separatedata-type object (dtype), one of

which is associated with each ndarray.

As with other container objects in Python, the contents of anndarraycan be accessed and modified byindexing or

slicingthe array (using, for example,Nintegers), and via the methods and attributes of thendarray.3

NumPy Reference, Release 1.9.2

Differentndarrayscan share the same data, so that changes made in onendarraymay be visible in another. That

is, an ndarray can be a"view"to another ndarray, and the data it is referring to is taken care of by the"base"ndarray.

ndarrays can also be views to memory owned by Pythonstringsor objects implementing thebufferorarray interfaces.Example

A 2-dimensional array of size 2 x 3, composed of 4-byte integer elements:>>>x= np .array([[1,2 ,3 ], [4,5 ,6 ]], np.int32)

>>>type(x) >>>x.shape (2, 3) >>>x.dtype dtype("int32")The array can be indexed using Python container-like syntax: >>>x[1,2]# i.e., the element of x in the*second*row,*third* column, namely, 6.For exampleslicingcan produce views of the array:>>>y= x[:, 1] >>>y array([2, 5]) >>>y[0]= 9 # this also changes the corresponding element in x >>>y array([9, 5]) >>>x array([[1, 9, 3], [4, 5, 6]])1.1.1Constructing arra ys

New arrays can be constructed using the routines detailed inArray creation routines, and also by using the low-level

ndarrayconstructor:ndarrayAn array object represents a multidimensional, homogeneous array of fixed-size items.classnumpy.ndarray

An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type

object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory,

whether it is an integer, a floating point number, or something else, etc.) Arrays should be constructed usingarray,zerosorempty(refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(...)) for instantiating an array.

For more information, refer to thenumpymodule and examine the the methods and attributes of an array.

Parameters

(for the __new__ method; see Notes below) shape: tuple of ints

Shape of created array.4Chapter 1. Array objects

NumPy Reference, Release 1.9.2

dtype: data-type, optional Any object that can be interpreted as a numpy data type. buffer: object exposing buffer interface, optional

Used to fill the array with data.

offset: int, optional

Offset of array data in buffer.

strides: tuple of ints, optional

Strides of data in memory.

order: {'C", 'F"}, optional

Row-major or column-major order.

See also:

array

Construct an array.

zeros

Create an array, each element of which is zero.

empty Create an array, but leave its allocated memory unchanged (i.e., it contains "garbage"). dtype

Create a data-type.

Notes There are two modes of creating an array using__new__: 1. Ifbufferis None, then onlyshape,dtype, andorderare used. 2. Ifbufferis an object exposing the buffer interface, then all keywords are interpreted. No__init__method is needed because the array is fully initialized after the__new__method.

Examples

These examples illustrate the low-levelndarrayconstructor. Refer to theSee Alsosection above for easier

ways of constructing an ndarray. First mode,bufferis None:>>>np.ndarray(shape=(2,2), dtype=float, order="F") array([[ -1.13698227e+002, 4.25087011e-303], [ 2.88528414e-306, 3.27025015e-309]]) #randomSecond mode: >>>np.ndarray((2,),buffer =np.array([1,2,3]), ...offset=np.int_().itemsize, ...dtype=int)# offset = 1*itemsize, i.e. skip first element array([2, 3])Attributes

1.1. The N-dimensional array (ndarray) 5

NumPy Reference, Release 1.9.2

TSame as self.transpose(), except that self is returned if self.ndim < 2. dataPython buffer object pointing to the start of the array"s data. dtypeData-type of the array"s elements. flagsInformation about the memory layout of the array. flatA 1-D iterator over the array. imagThe imaginary part of the array. realThe real part of the array. sizeNumber of elements in the array. itemsizeLength of one array element in bytes. nbytesTotal bytes consumed by the elements of the array. ndimNumber of array dimensions. shapeTuple of array dimensions. stridesTuple of bytes to step in each dimension when traversing an array. ctypesAn object to simplify the interaction of the array with the ctypes module. baseBase object if memory is from some other object.ndarray.T Same as self.transpose(), except that self is returned if self.ndim < 2.

Examples>>>x= np .array([[1.,2.],[3.,4.]])

>>>x array([[ 1., 2.], [ 3., 4.]]) >>>x.T array([[ 1., 3.], [ 2., 4.]]) >>>x= np .array([1.,2.,3.,4.]) >>>x array([ 1., 2., 3., 4.]) >>>x.T array([ 1., 2., 3., 4.])ndarray.data Python buffer object pointing to the start of the array"s data. ndarray.dtype

Data-type of the array"s elements.

Parameters

None

Returns

d: numpy dtype object

See also:

numpy.dtype

Examples>>>x

array([[0, 1], [2, 3]]) >>>x.dtype dtype("int32")6Chapter 1. Array objects

NumPy Reference, Release 1.9.2

>>>type(x.dtype) ndarray.flags

Information about the memory layout of the array.

Notes Theflagsobject can be accessed dictionary-like (as ina.flags["WRITEABLE"]), or by using low- ercasedattributenames(asina.flags.writeable). Shortflagnamesareonlysupportedindictionary access. Only the UPDATEIFCOPY, WRITEABLE, and ALIGNED flags can be changed by the user, via direct assignment to the attribute or dictionary entry, or by callingndarray.setflags.

The array flags cannot be set arbitrarily:

UPDATEIFCOPY can only be setFalse.

ALIGNED can only be setTrueif the data is truly aligned. WRITEABLE can only be setTrueif the array owns its own memory or the ultimate owner of the memory exposes a writeable buffer interface or is a string.

Arrays can be both C-style and Fortran-style contiguous simultaneously. This is clear for 1-dimensional

arrays, but can also be true for higher dimensional arrays. Even for contiguous arrays a stride for a given dimensionarr.strides[dim]may bearbi- traryifarr.shape[dim] == 1or the array has no elements. It doesnotgenerally hold that self.strides[-1] == self.itemsizefor C-style contiguous arrays orself.strides[0] == self.itemsizefor Fortran-style contiguous arrays is true.1.1. The N-dimensional array (ndarray) 7

NumPy Reference, Release 1.9.2

Attributes

C_CONTIGUOUS

(C)The data is in a single, C-style contiguous segment.

F_CONTIGUOUS

(F)The data is in a single, Fortran-style contiguous segment. OWN- DATA (O)The array owns the memory it uses or borrows it from another object.

WRITE-

ABLE (W)The data area can be written to. Setting this to False locks the data, making it read-only. A view (slice, etc.) inherits WRITEABLE from its base array at creation time, but a view of a writeable array may be subsequently locked while the base array remains writeable. (The opposite is not true, in that a view of a locked array may not be made writeable. However, currently, locking a base object does not lock any views that already reference it, so under that circumstance it is possible to alter the contents of a locked array via a previously created writeable view onto it.) Attempting to change a non-writeable array raises a RuntimeError exception.ALIGNED (A)The data and all elements are aligned appropriately for the hardware. UP-

DATEIF-

COPY (U)This array is a copy of some other array. When this array is deallocated, the base array will be updated with the contents of this array.FNCF_CONTIGUOUS and not C_CONTIGUOUS. FORCF_CONTIGUOUS or C_CONTIGUOUS (one-segment test).

BEHAVED

(B)ALIGNED and WRITEABLE.

CARRAY

(CA)BEHAVED and C_CONTIGUOUS.

FARRAY

(FA)BEHAVED and F_CONTIGUOUS and not C_CONTIGUOUS. ndarray.flat

A 1-D iterator over the array.

This is anumpy.flatiterinstance, which acts similarly to, but is not a subclass of, Python"s built-in

iterator object.

See also:

flatten Return a copy of the array collapsed into one dimension. flatiter

Examples>>>x= np .arange(1,7 ).reshape(2,3 )

>>>x array([[1, 2, 3], [4, 5, 6]]) >>>x.flat[3] 4 >>>x.T array([[1, 4], [2, 5], [3, 6]])8Chapter 1. Array objects

NumPy Reference, Release 1.9.2

>>>x.T.flat[3] 5 >>>type(x.flat) An assignment example: >>>x.flat= 3 ; x array([[3, 3, 3], [3, 3, 3]]) >>>x.flat[[1,4]]= 1 ; x array([[3, 1, 3], [3, 1, 3]])ndarray.imag

The imaginary part of the array.

Examples>>>x= np .sqrt([1+0j,0 +1j])

>>>x.imag array([ 0. , 0.70710678]) >>>x.imag.dtype dtype("float64")ndarray.real

The real part of the array.

See also:

numpy.real equivalent function

Examples>>>x= np .sqrt([1+0j,0 +1j])

>>>x.real array([ 1. , 0.70710678]) >>>x.real.dtype dtype("float64")ndarray.size

Number of elements in the array.

Equivalent tonp.prod(a.shape), i.e., the product of the array"s dimensions. Examples>>>x= np .zeros((3,5 ,2 ), dtype=np.complex128) >>>x.size 30
>>>np.prod(x.shape)

30ndarray.itemsize

Length of one array element in bytes.1.1. The N-dimensional array (ndarray) 9

NumPy Reference, Release 1.9.2

Examples

>>>x= np .array([1,2,3], dtype=np.float64) >>>x.itemsize 8 >>>x= np .array([1,2,3], dtype=np.complex128) >>>x.itemsize

16ndarray.nbytes

Total bytes consumed by the elements of the array. Notes Does not include memory consumed by non-element attributes of the array object. Examples>>>x= np .zeros((3,5,2), dtype=np.complex128) >>>x.nbytes 480
>>>np.prod(x.shape)*x.itemsize

480ndarray.ndim

Number of array dimensions.

Examples>>>x= np .array([1,2 ,3 ])

>>>x.ndim 1 >>>y= np .zeros((2,3 ,4 )) >>>y.ndim

3ndarray.shape

Tuple of array dimensions.

Notes

May be used to "reshape" the array, as long as this would not require a change in the total number of

elements

Examples>>>x= np .array([1,2 ,3 ,4 ])

>>>x.shape (4,) >>>y= np .zeros((2,3 ,4 )) >>>y.shape (2, 3, 4) >>>y.shape= ( 3,8 ) >>>y array([[ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0., 0., 0.]]) >>>y.shape= ( 3,6 )

Traceback (most recent call last):

File "" , line 1 , in 10Chapter 1. Array objects

NumPy Reference, Release 1.9.2

ValueError

: total size of new array must be unchanged

Traceback (most recent call last):

File "" , line 1 , in

ValueError

: total size of new array must be unchangedndarray.strides Tuple of bytes to step in each dimension when traversing an array. The byte offset of element(i[0], i[1], ..., i[n])in an arrayais:offset= sum (np.array(i)

*a.strides)A more detailed explanation of strides can be found in the "ndarray.rst" file in the NumPy reference guide.

See also:

numpy.lib.stride_tricks.as_strided Notes Imagine an array of 32-bit integers (each 4 bytes):x= np .array([[0,1 ,2 ,3 ,4 ], 5 6 7 8 9 ]], dtype np

int32)This array is stored in memory as 40 bytes, one after the other (known as a contiguous block of memory).

The strides of an array tell us how many bytes we have to skip in memory to move to the next position

along a certain axis. For example, we have to skip 4 bytes (1 value) to move to the next column, but 20

quotesdbs_dbs20.pdfusesText_26