All IT Courses 50% Off
Python Tutorials

NumPy

NumPy is a python package. It will stand for Numerical Python. This is considered as a library consisting of multidimensional array objects and also a collection of routines for managing arrays.

The ancestor of Numpy was developed by Jim Hugunin. There are other packages Numarray also developed that have some additional functionalities.

Operations using Numpy:

By using a developer who may perform the operations are:

  • Mathematical and logical operations on arrays
  • Fourier transforms and routines for the shape manipulations
  • These operations are linked to linear algebra. NumPy has default built-in functions for linear algebra and random number generation.

NumPy will be used with a scipy (scientific python) and mat-potlib. This is a combination that will be widely used as a replacement for Matlab, a popular platform for any technical computing. The Python alternative to Matlab is now seen as a modern and also complete programming language.

Python distribution will come bundled with the NumPy module. NumPy can also be installed using its lighter version – a popular python package installer pip.

All IT Courses 50% Off

pip install NumPy:

We have the best way to enable NumPy. Install binary packages to the operating system. These binaries will contain full scipy stack.

Windows

Python(x,y) is a free python distribution with scipy stack and spyder IDE for windows OS.

Linux

Package managers of respective Linux distributors which will be used to install one or more packages in scipy stack.

For Ubuntu

sudo apt-get install python-numpy 

python-scipy python-matplotlib ipython ipython notebook python-pandas 

python-sympy python-nose

How to install NumPy?

The core python will be installed with distutils and the Zlib module should be enabled.GNU gcc  C compiler must be available.

To install NumPy we have to run the following command

Python setup.py install

To test whether the NumPy module is properly installed we try to import it with a python prompt.

                 import numPy

        NumPy packages will be imported by the syntax import numPy as np

NumPy-Ndarray object:

The most important object that will be defined in NumPy is an N-dimensional array type that will be called ndarray. It will describe the collection of items of the same type. Items in the collection can be accessed using zero-based index. Any item extracted from ndarray object that is represented by the python object is one of the scalar types.

Ndarray

An instance of ndarray class will be built by different array creation routines. The most fundamental ndarray will be developed by using an array function in the NumPy that follows as

                             numpy.array 

It will develop an ndarray from any object exposing an array interface, or any method that will return an array.

There are many constructors which will take the parameters:

  • Object- Any object exposing the array interface method returns an array or any sequence.
  • dtype- That is desired data type of array
  • copy- By default the object will be copied.
  • order- C or F column or A
  • subok- That returned array is forced to be a base class array. Through, sub-classes passed through.
  • ndadmin- It specifies minimum dimensions of the resultant array.

Example:

import numpy as np 

a = np.array([2,3,5]) 

print a

Output

[2,3,5]

The ndarray object consists of a contiguous one-dimensional segment of computer memory, integrated with an indexing scheme that maps each item to a location in the memory block.

Numpy data types:

  • bool_ : Boolean will be stored in bytes
  • int_: The default integer type
  • intc: identical to C int
  • intp: Integer used for indexing
  • int8: Byte

Data Type objects:

A data type objects describes interpretation of fixed block of memory corresponding to an depending on the following aspects

  1.  Type of the data
  2.  Size of the data
  3.  Byte order
  4.  The structured type,the names of fields, data type of all fields and part of the memory block taken by each field.

Questions

  1. What is Numpy?
  2. What  are the advantages of Numpy?
Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button