Posts

Numpy Python Mini Projects: Weather Data Analysis

                 If you want analyse the weather, then this is program. It uses the real world datasets with arrays. It combines indexing, masking to perform the process. Let us create a python program to implement weather data analysis. Implementation: It starts from including numpy object. Temperature data is collected from the user for a week. The average temperature for a week is calculated and printed. Next, minimum and maximum temperature is calculated using built-in functions. Hot days, cool days, rainy days are categorised by the temperature. Standard deviation is also calculated. Finally the weather report is displayed to the screen. Code: import numpy as np1 #Get the temperature inputs from the user temp = np1.array(list(map(int, input("Enter the weekly temperature separated by space: ").split()))) print("Temperature of the week",temp) #Average temperature,minimum,maximum temperature   calculation ...

Numpy Python Mini Projects: Student Marks Analyzer

#Mini Project 1: Student Mark Analyzer Create a Numpy Project to implements Student Marks Analysis. It creates a set of students as array. It includes the students name and marks. Find the average, minimum and maximum marks. Print the values. Check for passed students, failed students and distinction students. If the mark is greater than 40, then the student passed the exam. Otherwise, the student failed in the exam. For finding the distinction, check the mark is greater than 75. Finally, print the results. Let us print the grade based on the marks. If the mark is greater than or equal to 90, grade is ‘A+’. Else, if the mark is greater than or equal to 75,then the grade is ‘A’. Else if, the mark is greater than 60,the grade is ‘B’. else if the mark is less than 40, the student’s grade is ‘C’ and ‘F’. Finally, print the grade. Complete Program import numpy as np1 # Student data creation students = np1.array([     "Ajay",     "Bob", ...

Aggregation in Numpy

  What is Aggregation?               It combines the multiple values together and forms a single value. The value depends on the operation. Let us implement some aggregate functions in numpy using python. Implementation:               This program includes the numpy object. It creates an array of elements. It has following functions to provide aggregate functions. Sum : adds all elements together. Mean: finds the mean value. Median: finds the middle highest value. Min: it gives you the minimum value. Max: it gives you the maximum value. Std: it calculates the standard deviation. Argmin: it displays index of minimum value. Argmax: it gives you the index of maximum value. Code: import numpy as np1 s_arr = np1.array([11,12,13,14,15,16,17]) print("The original array is:",s_arr) a_sum = np1.sum(s_arr) a_mean=np1.mean(s_ar...

How to implement Statistics functions in Numpy using Python?

               This is a branch of mathematics. It collects the data, analyses it and present it accordingly. It has many methods which is used to find sum, average, minimum , maximum and so on. Let us implement the list of functions given below….. Sum: to find the total of all elements. Mean: it find the average value. Median :it gives you the middle value after sorting. Maximum :this function gives you maximum value of the array. Minimum: it provides the minimum value of the array. Standard deviation: it finds the standard deviation value. Variance: it is the square of the standard deviation. Product: it multiplies all elements. Cumulative sum: it gives the running total. Cumulative product: it finds the running product value. Program to find values for all functions: import numpy as np1 s_arr = np1.array([11,12,13,14,15,16]) s_sum= np1.sum(s_arr) s_prod = np1.prod(s_arr) s_mean = np1.mean(s_arr) s_medi = np1....

Fancy indexing with a list of indices in python

                              It is one of the advanced indexing methods in Numpy. It makes you to find arbitrary elements in the list or array of index. Let us implement in different ways. ·        1D array ·        Reordering the elements of 1D array ·        2D array ·        Selecting specific elements 👉1D array:               This deals with Single dimensional array. First, it reads the array elements. Find the arbitrary elements. Finally, print the output. Code: import numpy as np1 s_arr = np1.array([11, 22, 33, 44, 55, 66, 77]) indices = [0, 2, 4] result = s_arr[indices] print("The indices are:",result) Output: The indices are: [11 33 55] 👉 Reordering the elements of 1D array:   ...

Boolean indexing in Python using Numpy

               It is the advanced indexing technique which makes you to select the elements of an array. It uses a Boolean mask (has two values True/False). Let us create this in 3 different ways as follows. Boolean indexing in 1D array Boolean indexing in 2D array Boolean indexing using Multiple conditions. Each one is explained with sample code as below. 👉Boolean indexing in 1D array               This program reads a single dimensional array as input. It uses a single condition to find Boolean mask. It finds the value and displays the result. 𜰘Code: import numpy as np1 s_arr = np1.array([11, 22, 33, 40, 55 ,66, 75]) mask = s_arr > 33 print("The resultant values are:\n",mask) result = s_arr[mask] print("The result which satisfies the condition s_arr>33:\n",result) 🖵Output: The resultant values are:   [False False False   True ...

Linear algrbra programs in Python Numpy

 What is Linear algebra?               It is a branch of mathematics which manipulates on matrices, vectors and linear equations.it isa foundation for Science, Engineering, Machine Learning, Data Science and so on.   Key Terms: Linear algebra deals with Scalars, Vectors, Matrices and Linear Equations. Let us discuss each one of it. Scalars: It deals with Single numbers.Eg :-5,3,4.5. Vector: It is an ordered lists of numbers. Matrices : It is a rectangular array of numbers. Linear Algebra: Equations where variables have power 1. Python: import numpy as np1 def main():     try:         # Example matrix         X = np1.array([[1, 1, 2],                       [1, 3, 2],      ...