My Day5 Python Learning: Deep Dive into NumPy

My Day5 Python Learning: Deep Dive into NumPy


Date: 2025-04-30


1. Introduction

Day 5 of my Python journey was all about NumPy and Seaborn, focusing on array operations, data distribution, and advanced statistical concepts. I delved into NumPy’s powerful array functionalities and explored various distributions using the Seaborn module. 📊🔢 Mastering these tools is key for data analysis, manipulation, and visualization.


2. Topics Covered

Article content

🔹 NumPy Basics

  • Creating Arrays: Understanding how to create arrays with np.array(), np.zeros(), np.ones(), and np.arange().
  • Array Indexing & Slicing: Accessing elements with simple indexing and slicing techniques, including multidimensional arrays.
  • Array Data Types: Exploring the different data types (int, float, complex, etc.) supported by NumPy arrays.
  • Copy vs View: Learning the difference between copying and viewing arrays, and when each is needed.
  • Reshaping Arrays: Using np.reshape() to alter array dimensions without changing the data.
  • Array Iteration: Looping through arrays using np.nditer() and iterating over multidimensional arrays.
  • Array Join & Split: Joining arrays with np.concatenate() and splitting them using np.split().
  • Array Search & Sort: Searching for elements with np.where() and sorting arrays using np.sort().
  • Array Filtering: Filtering arrays based on conditions using boolean indexing.

🔹 NumPy Random Module

  • Random Introduction: Overview of NumPy’s random number generation capabilities with np.random.
  • Data Distributions: Generating random values from distributions like normal, binomial, poisson, etc.
  • Random Permutation: Using np.random.permutation() to shuffle arrays and create random orderings.

🔹 Seaborn Module for Statistical Plots

  • Data Distribution Visualizations: Visualizing distributions using Seaborn with plots like distplot(), histplot(), kdeplot().
  • Normal Distribution: Using Seaborn to plot and analyze data following a normal distribution.
  • Binomial, Poisson, Uniform, and Logistic Distributions: Understanding the difference and visualizing them using sns.distplot().
  • Multinomial & Exponential Distributions: Simulating and visualizing data from these distributions.
  • Chi-Square & Rayleigh Distributions: Generating and visualizing Chi-Square and Rayleigh distributions for statistical modeling.
  • Pareto & Zipf Distributions: Exploring power-law distributions and their applications in real-world scenarios.


3. Practice Code Snippets

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

# NumPy Array Creation and Operations
arr = np.array([1, 2, 3, 4, 5])
reshaped_arr = arr.reshape(1, 5)
print("Reshaped Array:", reshaped_arr)

# NumPy Array Slicing
sliced_arr = arr[1:4]
print("Sliced Array:", sliced_arr)

# NumPy Random Distribution (Normal)
random_normal = np.random.normal(loc=0, scale=1, size=1000)
sns.histplot(random_normal, kde=True)
plt.title("Normal Distribution")
plt.show()

# NumPy Random Distribution (Binomial)
random_binomial = np.random.binomial(n=10, p=0.5, size=1000)
sns.histplot(random_binomial, kde=True)
plt.title("Binomial Distribution")
plt.show()

# Seaborn Distribution Plot (Exponential)
random_exponential = np.random.exponential(scale=1, size=1000)
sns.histplot(random_exponential, kde=True)
plt.title("Exponential Distribution")
plt.show()

# Visualizing a Chi-Square Distribution with Seaborn
random_chi_square = np.random.chisquare(df=2, size=1000)
sns.histplot(random_chi_square, kde=True)
plt.title("Chi-Square Distribution")
plt.show()
        

4. Reflection

Mastering NumPy’s array handling and diving into random number generation for various statistical distributions gave me a new appreciation for the power and flexibility of Python in data analysis. Seaborn, as a visualization tool, made these concepts even more approachable by allowing me to see the distributions in action. 📊🔍


5. Tomorrow's Goals

  • Deep dive into NumPy’s Linear Algebra Functions
  • Explore Seaborn Pairplot for multivariate data visualization
  • Continue experimenting with custom distributions and statistical plots


6. Reference


#PythonDay5 #NumPy #Seaborn #DataScience #100DaysOfCode #PythonProgress #2025Learning


To view or add a comment, sign in

More articles by Dinesh S J

Insights from the community

Others also viewed

Explore topics