Search

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

NumPy - Part1

NumPy (Numerical Python) is the fundamental package for scientific computing in Python. It provides a multidimensional arrayobject, various derived objects (such as masked arrays and matrices), and an assortment of routines for fast operations on arrays,including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more.


Why we need numpy when we have list?/Why numpy is so popular?

  • Provide faster operation for Large Scale operation
  • Behind the scene optimizations written in C
  • Vectorization via broadcasting(avoiding loops)s
  • Backbone of other python scientifi c packages


Numpy dataTypes and Attributes

Main datatype of Numpy is ndarray, where ndarray represent n dimentional array.

import numpy as np
import pandas as pd #Details of pandas library will be cover in Pandas chapter.
a1 = np.array([1,2,3])
print(a1)
print("Type of the array is {}".format(type(a1)))
print("\nData type of the array is {}".format(a1.dtype))
print("\nShape of the array is {}".format(a1.shape))
print("\nSize of the array is {}".format(a1.size))
print("\nDimention of the array is {}".format(a1.ndim))
print("\n",pd.DataFrame(a1))

O/P

[1 2 3]
Type of the array is <class 'numpy.ndarray'>

Data type of the array is int64

Shape of the array is (3,)

Size of the array is 3

Dimention of the array is 1

    0
0  1
1  2
2  3

Compilation vs. interpretation - advantages and disadvantages


Compilation vs. interpretation - advantages and disadvantages


COMPILATION
INTERPRETATION

ADVANTAGES

  • the execution of the translated code is usually faster;
  • only the user has to have the compiler - the end-user may use the code without it;
  • the translated code is stored using machine language - as it is very hard to understand it, your own inventions and programming tricks are likely to remain your secret.
  • you can run the code as soon as you complete it - there are no additional phases of translation;
  • the code is stored using programming language, not the machine one - this means that it can be run on computers using different machine languages; you don't compile your code separately for each different architecture.

DISADVANTAGES

  • the compilation itself may be a very time-consuming process - you may not be able to run your code immediately after any amendment;
  • you have to have as many compilers as hardware platforms you want your code to be run on.
  • don't expect that interpretation will ramp your code to high speed - your code will share the computer's power with the interpreter, so it can't be really fast;
  • both you and the end user have to have the interpreter to run your code.