Posts

Showing posts from 2026

Python NumPy Mini Projects: Movie Ratings Analyzer

              It is a beginner friendly mini project in NumPy mini Project. It reads the user reviews. Analyzes the reviews and make a good statistical reports. Let us implement this as follows… Implementation: This implementation starts from including numpy object. The movies names are assigned for an array. Ratings are recorder in another array. 4 parameters are calculated here. first, average of the reviews. It uses mean() function. Next, maximum and minimum calculation.This uses max() and min() functions. Finally, median rating is calculated by median(). These values are displayed. At last, the datas are sorted and displayed. Code: import numpy as np1 # Movie names movies = np1.array([     "Avengers:Doomsday",     "Spider-Man: Brand New Day",     "Jailer2",     "Titanic",     "Inception" ]) # Ratings out of 10 ratings = np1.array([...

Python Numpy MiniProjects : Implementation of Tic-Tac-Toe game

       Tic-Tac-Toe is a thinking game between two opponents. Each one has a symbol ‘o’ or ‘x’. The first person who built the three consecutive rows or columns or diagonals win the game. Opponent player will keep on move their symbols to make sure that opposite person should not make the three consecutive moves. Let us implement it using Numpy Arrays Implementation: import numpy as np1 # First a 3x3 game board is created board = np1.full((3, 3), "-") def display_board():     print("\nCurrent Board:")     print(board) def check_winner(player):     # Check for rows to find three consecutive moves     for row in board:         if np1.all(row == player):             return True     # Check columns for three consecutive columns     for col in board.T:   ...

Python Numpy Mini Projects: Sudoku Board Validator

Sudoku Board is mathematical board which has dimensions 9x9. You have to fill the numbers from 1 to 9 without duplication in columns or rows. Validation can be done by as follows. ·        Each row should have numbers 1-9 without duplicates. ·        Each column needs to filled with numbers 1-9 without repetition. ·        In the same way, each sub-grid should be filled with numbers 1-9 without overlapping. Program implementation: This code starts from importing numpy library. Two functions are created for validating the sudoku board.one is for shape. Another one is for elements. Input of the sudoku board is created with elements. First, shape is checked for number of rows and columns. Next one is for each row, each column and sub grid. Each one of the groups should be filled with 1to 9 without any repetition. Finally, the output is printed. Code: import numpy as np1 d...

Python Numpy Mini Projects: Cricket Score Analysis

              This program analyses a cricket player’s scores across many matches he/she played. It is a moderate mini project to implement. It needs some array to store the data, many functions are used. Here, is the implementation. Implementation: This implementation starts with include numpy and its object. The score details are included in the array and displayed. The following daata’s are calculated. Total runs,Average and highest scores are displayed. Century and half century values are noted. Scores above the average are displayed. Standard deviation values are calculated and displayed. Finally, best match and score are displayed. Code: import numpy as np1 #score board scores = np1.array(list(map(int, input("Enter the Cricket score of the player separated by space: \n ").split()))) print("Scores are displayed here:\n", scores) print("\nTotal Runs of the player:", np1.sum(scores)) print("Average Score of the pla...

Python Numpy Mini Projects: Simple Attendance System

               Attendance system is a common system which marks the student’s entry. when they are getting in to the school or college, it puts the attendance. Present means 1 and absent means 0. Let us implement this program. Implementation: This program creates a student array. Next, attendance entry matrix is created.   Attendance analysis is done as follows.. First, attendance percentage for each student is created according to the data. Next, below 75% attendance students are displayed separately. Code: import numpy as np1 # Student names students = np1.array(["Ajay", "Bob", "Charan", "Dia", "Marya", "Henry"]) # Attendance for 6 days (1 = Present, 0 = Absent) attendance = np1.array([     [1, 1, 0, 1, 1, 1],       [1, 0, 1, 1, 0, 0],       [1, 1, 1, 1, 1, 1],       [0, 1, 0, 1, 1, 0],       [1, 1, 1, 0, 1, 1],...

Python Miniprojects : Simulation of a dice roll

               Dice has 6 faces. Each one has a value. Here, ‘random.randint()’ function is used. Let us implement this. ·        Simple dice roll ·        Multiple dice roll ·        Using function ·        Object oriented approach Simple dice roll:               It uses randint() function to roll a dice with in the range 1 to 6. Code:   import random dice_result = random.randint(1, 6) print(f"The dice rolled: {dice_result}") Output: The dice rolled: 6 Multiple dice roll:               This method gets the input from the user about how many dice to roll. Based on the input, it rolls the dice and display the input. Code: import random num_dice = int(input("Enter...

Numpy Python Mini projects: Expense Tracker

               Expense tracker is one of the important applications in Numpy. It tracks the daily expenses, calculates the highest, lowest, average and total expenses. Let us implement the expense tracker in numpy. Implementation: First, built-in numpy library is included. It creates an array to read the input from the user. Print the array of elements. Next, total expenses are calculated by adding all elements in the array using sum() function. To find the ‘Average’ value by using mean() function in the numpy package. Other functions are included as follows. ‘max()’: it gives you the maximum value. ‘min()’: it finds the minimum value. It also checks the expense value is greater than 150 and calculates the sum and prints it. Code: import numpy as np1 # Let us create daily expenses s_expenses = np1.array(list(map(int, input("Enter the weekly expenses separated by space: ").split()))) print("Expenses of the week:", s_ex...

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],      ...

Array operations in NumPy – Aggregate and Advanced Operations:

               Arrays in numpy has variety of operations like element-wise arithmetic, Scalar Operations, Aggregate and advanced functions. The basic operations are already discussed. Now,we discuss about the aggregate and advanced functions. Python Numpy Code for Aggregate and Advanced Operations:               This code starts from importing Numpy library. First,create two arrays with elements. Next,Aggregate functions like sum of all elements,Mean value,max and min values are calculated with built-in functions. Advanced functions like Dot product,square root and exponential are also calculated with built-in function. Code:   import numpy as np # Let us Create two arrays s_arr1 = np.array([1, 3, 5, 7]) s_arr2 = np.array([2, 4, 6, 8]) #Aggregate functions print("Sum:", np.sum(s_arr1))             ...

Scalar Multiplication in Numpy

               Here, we use Scalar multiplications in different ways. Let us try three methods listed as follows.. ·        1D array scalar multiplication ·        2D array scalar multiplication ·        Different scalars for each column The sample code is given below. 1D array scalar multiplication:   This code multiplies the array by 3. First, it creates an array of elements. Each element is multiplied by 3. The result is displayed. Code: import numpy as np1 # Create an array with elements s_arr = np1.array([1, 3, 5, 7, 9, 11, 13, 15]) # Scalar multiplication by 3 result = s_arr * 3 print("Original array:", s_arr)    print("Multiplied by 3:", result) Output: Original array: [ 1   3   5   7   9 11 13 15] Multiplied by 3: [ 3   9 15 21 27 33 39 45] 2D array scalar multiplication: ...

How to implement element-wise addition,subtraction and multiplication in Numpy?

              Array is a collection of similar data elements. When you implement the arithmetic operations, you have to do each element. Let us implement this as follows. Element-wise Arithmetic Operations in Numpy:               It starts from importing numpy library. First, two arrays are included as input. Element wise operations are performed and result is printed. Code: import numpy as np1 # Two arrays as input s_arr1 = np1.array([11, 22, 33, 44]) s_arr2 = np1.array([5, 10, 15, 20]) # Arithmetic operations on element wise print("Element wise Arithmetic Operations:") print("Addition:", s_arr1 + s_arr2)         print("Subtraction:", s_arr2 - s_arr1)      print("Multiplication:", s_arr1 * s_arr2)   Output: Element wise Arithmetic Operations: Addition: [16 32 48 64] Subtraction: [ -6 -12 -18 -24] ...

Indexing and slicing arrays in python numpy

               Indexing is the process of retrieving specific elements, whereas slicing extracts subarrays in a range. Both methods support negative indices and returns the original array elements. Mainly, these two methods make the user to access, extract the elements and manipulates the array in efficient manner. Let us discuss the methods with sample code as follows… Indexing in Numpy:               It supports three methods as follows. ·        Single element indexing ·        Multi-dimensional indexing ·        Index arrays The sample code is given below.. Single element indexing:               It follows list concept in python. Code: import numpy as np1 s_arr = np1.arange(10)    # [0,1,2,3,4,...