Numpy in Python

Kajol ajab   24 January,2020  

Introduction

Numpy is an array-processing package.

It provides a high-performance multidimensional array oject & tools for working with this array.

Its most important type is an array type called ndarray.

NumPy is suitable for creating and working with arrays because it offers useful routines, enables performance boosts, and allows you to write concise code.

Basic topics with an examples:

  1. Array

    Consider any array and find type of array,dimensions, size, shape,dtype of array

    2. Array creation

        a. create an array from list with type float

        b. create an array from tuple

        c. create a 3X2 array with all zeros

        d. create an array with random values

        e. create a sequence of intergers from 0 to 20 with steps of 5

        f. create sequential array with 8 values between 0 to 3

        g. reshape 3X4 array to 2X2X3 array

        i. Flatten array

 

Playing with array

 

    3. Array Indexing

        a. Slicing

        b. Integer array indexing

        c. Boolean array indexing

 

Conclusion

NumPy's arrays are more compact than Python lists -- a list of lists as you describe, in Python, would take at least 20 MB or so, while a NumPy 3D array with single-precision floats in the cells would fit in 4 MB. Access in reading and writing items is also faster with NumPy.

0
Like