Spaces:
Sleeping
Sleeping
File size: 1,722 Bytes
d4e5a7c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
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)
|