Posts

60.Plotting and Visualization-Matplotlib

Image
Matplotlib is one of the most popular Python packages used for data visualization. It is a cross-platform library for making 2D plots from data in arrays.Matplotlib is written in Python and makes use of NumPy.It was introduced by John Hunter in the year 2002. One of the greatest benefits of visualization is that it allows us visual access to huge amounts of data in easily digestible visuals. Matplotlib consists of several plots like line, bar, scatter, histogram etc. Anaconda is a free and open source distribution of the Python and R programming languages for large-scale data processing, predictive analytics, and scientific computing. The distribution makes package management and deployment simple and easy. Matplotlib and lots of other useful (data) science tools form part of the distribution.If you have anaconda installed on your computer matplotlib can be used directly else install matplotlib. Read the details and history Lets plot a simple sin wave using matplotlib 1.To begin with, ...

59.Numpy and Linear Algebra

The Linear Algebra module of NumPy offers various methods to apply linear algebra on any numpy array. One can find: rank, determinant, trace, etc. of an array. eigen values of matrices matrix and vector products (dot, inner, outer,etc. product), matrix exponentiation solve linear or tensor equations and much more! Multiplication of matrix using dot function (@ operator can also be used) import numpy as np x=np.array([[1,2,3],[4,5,6]]) y=np.array([2,4,1]) print(x.dot(y)) print(x@y) print(np.dot(x,y)) [13 34] [13 34] [13 34] import numpy as np   A = np.array([[6, 1, 1],                         [4, -2, 5],                         [2, 8, 7]])   Rank of a matrix print("Rank of A:", np.linalg.matrix_rank(A)) Rank of A: 3 Diagonals of a matrix print(np.diag(A)) [ 6 -2 7] print(np.diag(A,k=1)) # above the main diagonal [1 5] print(np.diag(A,k=-1)) #below ...

58.Random Numbers

Image
Random numbers are widely used in science and engineering computations.They can be used to simulate noisy data, or to model physical phenomena like the distribution of velocities of molecules in a gas, or to act like the roll of dice in a game. There are even methods for numerically evaluating multi-dimensional integrals using random numbers. The basic idea of a random number generator is that it should be able to produce a sequence of numbers that are distributed according to some predetermined distribution function. NumPy provides a number of such random number generators in its library  numpy.random . Here we focus on three:  rand, randn, and randint. Random means something that can not be predicted logically.Computers work on programs, and programs are definitive set of instructions. So it means there must be some algorithm to generate a random number as well. If there is a program to generate random number it can be predicted, thus it is not truly random. Random numbers g...

50.Programming Assignment 11- using OOPs

1.create class Arith to do arithmetic operation.It contains a member function read() to read the two numbers and add() method to find the sum. You can add more methods to the class to incorporate more functionality.class Arith: 2.create a class Rectangle .A constructor is used to initialize the object values. Member function area() to compute the area of the rectangle ( university question) 3.Create a class car with attributes model, year and price and a method cost() for displaying the prize. Create two instance of the class and call the method for each instance.(university question) 4.Create a class student with attribute name and roll number and a method dataprint() for displaying the same. Create two instance of the class and call the method for each instance.( university question) 5.Create a class Person with attributes name, age salary and a method display() for showing the details. Create two instances of the class and call the method for each instance. 6.Define a class Mobile t...

57.Numpy-Matrix and Matrix operations

Matrices and Matrix Arithmetic Matrices are a foundational element of linear algebra. Matrices are used throughout the field of machine learning in the description of algorithms and processes such as the input data variable (X) when training an algorithm.A matrix is a two-dimensional array of scalars with one or more columns and one or more rows. Defining a Matrix We can represent a matrix in Python using a two-dimensional NumPy array. A NumPy array can be constructed given a list of lists. For example, below is a 2 row, 3 column matrix. # create matrix from numpy import array A = array([[1, 2, 3], [4, 5, 6]]) print(A) o/p: [[1 2 3] [4 5 6]] Matrix Addition # matrix addition from numpy import array # define first matrix A = array([[1, 2, 3],[4, 5, 6]]) print(A) # define second matrix B = array([[1, 2, 3],[4, 5, 6]]) print(B) # add matrices C = A + B  # or  np.add(A,b) print(C) o/p: [[1 2 3] [4 5 6]] [[1 2 3] [4 5 6]] [[ 2 4 6] [ 8 10 12]] Matrix Subtraction # matrix subtra...

56.Numpy Basics- Creating arrays, arithmetic,indexing and slicing,functions

Image
NumPy (Numerical Python) is a popular Python library for numerical and scientific computing. It provides support for large, multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on these arrays. NumPy is a fundamental library for data manipulation and analysis in the Python ecosystem and is widely used in various scientific and engineering applications. Here are some of the key features and capabilities of NumPy: Multidimensional Arrays: NumPy provides the ndarray object, which is a highly efficient and flexible array data structure. These arrays can have any number of dimensions and are the building blocks for many scientific and mathematical computations. Element-Wise Operations: NumPy allows you to perform element-wise operations on arrays, making it easy to apply mathematical operations to entire arrays without explicit loops. Mathematical Functions: NumPy includes a wide range of mathematical functions for operations like basic arit...