Spaces:
Sleeping
Sleeping
eaglelandsonce
commited on
Create 3_NumpyBasics.py
Browse files- pages/3_NumpyBasics.py +65 -0
pages/3_NumpyBasics.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
def example1():
|
5 |
+
array = np.array([1, 2, 3, 4, 5])
|
6 |
+
return array
|
7 |
+
|
8 |
+
def example2():
|
9 |
+
array = np.arange(0, 10, 2)
|
10 |
+
return array
|
11 |
+
|
12 |
+
def example3():
|
13 |
+
array = np.linspace(0, 1, 5)
|
14 |
+
return array
|
15 |
+
|
16 |
+
def example4():
|
17 |
+
array = np.zeros((3, 3))
|
18 |
+
return array
|
19 |
+
|
20 |
+
def example5():
|
21 |
+
array = np.ones((2, 3))
|
22 |
+
return array
|
23 |
+
|
24 |
+
def example6():
|
25 |
+
array = np.eye(4)
|
26 |
+
return array
|
27 |
+
|
28 |
+
def example7():
|
29 |
+
array = np.random.random((2, 3))
|
30 |
+
return array
|
31 |
+
|
32 |
+
def example8():
|
33 |
+
array = np.random.randint(1, 10, size=(3, 3))
|
34 |
+
return array
|
35 |
+
|
36 |
+
def example9():
|
37 |
+
array = np.array([1, 2, 3, 4, 5])
|
38 |
+
reshaped_array = array.reshape((5, 1))
|
39 |
+
return reshaped_array
|
40 |
+
|
41 |
+
def example10():
|
42 |
+
array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
|
43 |
+
transposed_array = np.transpose(array)
|
44 |
+
return transposed_array
|
45 |
+
|
46 |
+
examples = [
|
47 |
+
("Example 1: Create a simple array", example1),
|
48 |
+
("Example 2: Create an array with a range of values using arange", example2),
|
49 |
+
("Example 3: Create an array with evenly spaced values using linspace", example3),
|
50 |
+
("Example 4: Create a 3x3 matrix of zeros", example4),
|
51 |
+
("Example 5: Create a 2x3 matrix of ones", example5),
|
52 |
+
("Example 6: Create an identity matrix", example6),
|
53 |
+
("Example 7: Create a 2x3 matrix with random values", example7),
|
54 |
+
("Example 8: Create a 3x3 matrix with random integers", example8),
|
55 |
+
("Example 9: Reshape a 1D array to a 2D array", example9),
|
56 |
+
("Example 10: Transpose a 2D array", example10),
|
57 |
+
]
|
58 |
+
|
59 |
+
st.title("NumPy Essentials with Streamlit")
|
60 |
+
|
61 |
+
for title, func in examples:
|
62 |
+
st.header(title)
|
63 |
+
if st.button(f"Run {title.split(':')[0]}"):
|
64 |
+
result = func()
|
65 |
+
st.write("Output:", result)
|