Spaces:
Sleeping
Sleeping
import streamlit as st | |
import numpy as np | |
# App title | |
st.title('NumPy Concepts: From Scratch to Advanced') | |
# Sidebar for navigation | |
st.sidebar.title("Navigation") | |
options = st.sidebar.radio("Go to", ["Home", "Array Basics", "Advanced Operations", "Linear Algebra"]) | |
# Home page | |
if options == "Home": | |
st.header("Welcome to NumPy Learning Hub!") | |
st.write(""" | |
This app will guide you through various concepts of NumPy, starting from the basics to advanced levels. | |
Use the sidebar to navigate through different sections. | |
""") | |
# Array Basics page | |
elif options == "Array Basics": | |
st.header("Array Basics") | |
st.write("Learn about creating arrays and basic operations.") | |
# Creating arrays | |
st.subheader("Creating Arrays") | |
array1 = np.array([1, 2, 3, 4, 5]) | |
st.write("1D Array:", array1) | |
array2 = np.array([[1, 2], [3, 4]]) | |
st.write("2D Array:", array2) | |
# Basic operations | |
st.subheader("Basic Operations") | |
array_sum = np.sum(array1) | |
st.write("Sum of array:", array_sum) | |
array_mean = np.mean(array1) | |
st.write("Mean of array:", array_mean) | |
# Advanced Operations page | |
elif options == "Advanced Operations": | |
st.header("Advanced Operations") | |
st.write("Explore advanced NumPy operations like broadcasting and slicing.") | |
array3 = np.arange(10) | |
st.write("Original array:", array3) | |
st.subheader("Slicing") | |
st.write("Sliced array (2:5):", array3[2:5]) | |
st.subheader("Broadcasting") | |
array4 = np.array([1, 2, 3]) | |
array_broadcasted = array4 + 5 | |
st.write("Broadcasted array:", array_broadcasted) | |
# Linear Algebra page | |
elif options == "Linear Algebra": | |
st.header("Linear Algebra") | |
st.write("Dive into linear algebra concepts with NumPy.") | |
# Matrix multiplication | |
st.subheader("Matrix Multiplication") | |
matrix1 = np.array([[1, 2], [3, 4]]) | |
matrix2 = np.array([[5, 6], [7, 8]]) | |
matrix_product = np.dot(matrix1, matrix2) | |
st.write("Matrix 1:", matrix1) | |
st.write("Matrix 2:", matrix2) | |
st.write("Matrix product:", matrix_product) | |
# Eigenvalues and eigenvectors | |
st.subheader("Eigenvalues and Eigenvectors") | |
matrix3 = np.array([[4, -2], [1, 1]]) | |
eigenvalues, eigenvectors = np.linalg.eig(matrix3) | |
st.write("Matrix:", matrix3) | |
st.write("Eigenvalues:", eigenvalues) | |
st.write("Eigenvectors:", eigenvectors) | |