Spaces:
Sleeping
Sleeping
import streamlit as st | |
import numpy as np | |
def example1(): | |
array = np.array([1, 2, 3, 4, 5]) | |
return array | |
def example2(): | |
array = np.arange(0, 10, 2) | |
return array | |
def example3(): | |
array = np.linspace(0, 1, 5) | |
return array | |
def example4(): | |
array = np.zeros((3, 3)) | |
return array | |
def example5(): | |
array = np.ones((2, 3)) | |
return array | |
def example6(): | |
array = np.eye(4) | |
return array | |
def example7(): | |
array = np.random.random((2, 3)) | |
return array | |
def example8(): | |
array = np.random.randint(1, 10, size=(3, 3)) | |
return array | |
def example9(): | |
array = np.array([1, 2, 3, 4, 5]) | |
reshaped_array = array.reshape((5, 1)) | |
return reshaped_array | |
def example10(): | |
array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | |
transposed_array = np.transpose(array) | |
return transposed_array | |
examples = [ | |
("Example 1: Create a simple array", example1), | |
("Example 2: Create an array with a range of values using arange", example2), | |
("Example 3: Create an array with evenly spaced values using linspace", example3), | |
("Example 4: Create a 3x3 matrix of zeros", example4), | |
("Example 5: Create a 2x3 matrix of ones", example5), | |
("Example 6: Create an identity matrix", example6), | |
("Example 7: Create a 2x3 matrix with random values", example7), | |
("Example 8: Create a 3x3 matrix with random integers", example8), | |
("Example 9: Reshape a 1D array to a 2D array", example9), | |
("Example 10: Transpose a 2D array", example10), | |
] | |
st.title("NumPy Essentials with Streamlit") | |
for title, func in examples: | |
st.header(title) | |
if st.button(f"Run {title.split(':')[0]}"): | |
result = func() | |
st.write("Output:", result) | |