Skip to content

Commit cd80ebb

Browse files
Add files via upload
1 parent 0440eb0 commit cd80ebb

5 files changed

+206
-0
lines changed

Diff for: FAQ03 - NumPy/demoPrompt06.a.01_ChatGPT+NumPy.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as np
2+
3+
# Create a 3-dimensional array with numbers from 0 to 29
4+
a = np.arange(30).reshape(2, 3, 5)
5+
6+
# Print the array and its properties
7+
print("Array:")
8+
print(a)
9+
print("Shape:", a.shape)
10+
print("Dimensions:", a.ndim)
11+
print("Data type:", a.dtype.name)
12+
print("Item size:", a.itemsize)
13+
print("Number of elements:", a.size)
14+
15+
# Fill a matrix with random integer values
16+
rng = np.random.default_rng()
17+
matrix = rng.integers(low=0, high=100, size=(3, 3))
18+
19+
# Find max, min, and sum
20+
print("Matrix:")
21+
print(matrix)
22+
print("Max element:", np.max(matrix))
23+
print("Min element:", np.min(matrix))
24+
print("Sum of elements:", np.sum(matrix))

Diff for: FAQ03 - NumPy/demoPrompt10.a.01_ChatGPT+NumPy.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import tkinter as tk
2+
import numpy as np
3+
from PIL import Image, ImageTk
4+
5+
root = tk.Tk()
6+
7+
# Create a 2D array (e.g., grayscale image)
8+
array = np.ones((400, 400)) * 150
9+
10+
# Convert the NumPy array to a PIL Image object
11+
img = Image.fromarray(array)
12+
13+
# Create a Tkinter PhotoImage object from the PIL Image
14+
tk_img = ImageTk.PhotoImage(image=img)
15+
16+
# Create a Tkinter Label widget and add the PhotoImage to it
17+
label = tk.Label(root, image=tk_img)
18+
label.pack()
19+
20+
root.mainloop()

Diff for: FAQ03 - NumPy/demoPrompt10.a.02_ChatGPT+NumPy.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
import numpy as np
4+
5+
class MatrixCalculatorApp:
6+
def __init__(self, root):
7+
self.root = root
8+
self.root.title("Matrix Calculator")
9+
10+
# Create UI components
11+
self.label_matrix_a = ttk.Label(root, text="Matrix A:")
12+
self.entry_matrix_a = ttk.Entry(root, width=20)
13+
self.label_matrix_b = ttk.Label(root, text="Matrix B:")
14+
self.entry_matrix_b = ttk.Entry(root, width=20)
15+
self.btn_add = ttk.Button(root, text="Add", command=self.perform_addition)
16+
self.btn_multiply = ttk.Button(root, text="Multiply", command=self.perform_multiplication)
17+
self.result_label = ttk.Label(root, text="Result:")
18+
19+
# Arrange UI components using grid layout
20+
self.label_matrix_a.grid(row=0, column=0, padx=10, pady=5)
21+
self.entry_matrix_a.grid(row=0, column=1, padx=10, pady=5)
22+
self.label_matrix_b.grid(row=1, column=0, padx=10, pady=5)
23+
self.entry_matrix_b.grid(row=1, column=1, padx=10, pady=5)
24+
self.btn_add.grid(row=2, column=0, columnspan=2, padx=10, pady=5)
25+
self.btn_multiply.grid(row=3, column=0, columnspan=2, padx=10, pady=5)
26+
self.result_label.grid(row=4, column=0, columnspan=2, padx=10, pady=5)
27+
28+
def perform_addition(self):
29+
try:
30+
matrix_a = np.array(eval(self.entry_matrix_a.get()))
31+
matrix_b = np.array(eval(self.entry_matrix_b.get()))
32+
result = matrix_a + matrix_b
33+
self.result_label.config(text=f"Result: {result}")
34+
except Exception as e:
35+
self.result_label.config(text=f"Error: {str(e)}")
36+
37+
def perform_multiplication(self):
38+
try:
39+
matrix_a = np.array(eval(self.entry_matrix_a.get()))
40+
matrix_b = np.array(eval(self.entry_matrix_b.get()))
41+
result = np.dot(matrix_a, matrix_b)
42+
self.result_label.config(text=f"Result: {result}")
43+
except Exception as e:
44+
self.result_label.config(text=f"Error: {str(e)}")
45+
46+
if __name__ == "__main__":
47+
root = tk.Tk()
48+
app = MatrixCalculatorApp(root)
49+
root.mainloop()

Diff for: FAQ03 - NumPy/demoPrompt10.a.03_ChatGPT+NumPy.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from tkinter import*
2+
import numpy as np
3+
4+
root = Tk()
5+
root.title("Numpy Module")
6+
root.geometry("700x400")
7+
8+
def find():
9+
global sc1 , sc2
10+
sc1.set("")
11+
sc2.set("")
12+
if entry.get():
13+
if entry_1.get():
14+
if entry_3.get():
15+
r = int(entry.get())
16+
c = int(entry_1.get())
17+
#n = list(map(int, input().split()))
18+
n = (entry_3.get().split())
19+
matrix = np.array(n).reshape(r, c)
20+
a = matrix.size
21+
b = matrix.shape
22+
sc1.set(a)
23+
sc2.set(b)
24+
25+
sc1=StringVar('')
26+
sc2=StringVar('')
27+
label = Label(root,text="Enter the number of row",font=('arial',20),fg="blue")
28+
label.place(x=40,y=70)
29+
30+
entry = Entry(root,justify=CENTER)
31+
entry.place(x=350, y=80)
32+
33+
label_1 = Label(root,text="Enter the number of col",font=('arial',20),fg="blue")
34+
label_1.place(x=40,y=130)
35+
36+
entry_1 = Entry(root, justify=CENTER)
37+
entry_1.place(x=350, y=142)
38+
39+
label_3 = Label(root,text="Enter the entries in a single line (separated by space):",font=('arial',20),fg="blue")
40+
label_3.place(x=40,y=180)
41+
42+
entry_3 = Entry(root,justify=CENTER,width=40)
43+
entry_3.place(x=400, y=220)
44+
45+
label_2 = Label(root,text="The size of matrix is :",font=('arial',20),fg="blue")
46+
label_2.place(x=30,y=250)
47+
48+
entry_2 = Entry(root,justify=CENTER,textvariable=sc1)
49+
entry_2.place(x=330, y=260,height=25)
50+
51+
label_4 = Label(root,text="The shape of matrix in row and col :",font=('arial',20),fg="blue")
52+
label_4.place(x=30,y=300)
53+
54+
entry_4 = Entry(root,justify=CENTER,textvariable=sc2)
55+
entry_4.place(x=470, y=310,height=25)
56+
57+
button = Button(root,width=10, justify=CENTER ,text="Calculate",command=find)
58+
button.place(x=250, y=360)
59+
60+
root.mainloop()

Diff for: FAQ03 - NumPy/demoPrompt10.b._ChatGPT+NumPy.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import tkinter as tk
2+
from tkinter import ttk
3+
import numpy as np
4+
5+
class NumPyTkinterApp:
6+
def __init__(self, root):
7+
self.root = root
8+
self.root.title("NumPy with Tkinter")
9+
10+
# Create a frame
11+
self.frame = ttk.Frame(self.root)
12+
self.frame.pack(padx=10, pady=10)
13+
14+
# Create a label
15+
self.label = ttk.Label(self.frame, text="NumPy Array:")
16+
self.label.grid(row=0, column=0, padx=5, pady=5)
17+
18+
# Create an entry widget
19+
self.entry = ttk.Entry(self.frame)
20+
self.entry.grid(row=0, column=1, padx=5, pady=5)
21+
22+
# Create a button to compute the mean
23+
self.button = ttk.Button(self.frame, text="Compute Mean", command=self.compute_mean)
24+
self.button.grid(row=1, columnspan=2, padx=5, pady=5)
25+
26+
# Create a label to display the result
27+
self.result_label = ttk.Label(self.frame, text="")
28+
self.result_label.grid(row=2, columnspan=2, padx=5, pady=5)
29+
30+
def compute_mean(self):
31+
# Get the input from the entry widget
32+
input_text = self.entry.get()
33+
34+
try:
35+
# Convert the input to a NumPy array
36+
arr = np.array(eval(input_text))
37+
38+
# Compute the mean of the array
39+
mean_value = np.mean(arr)
40+
41+
# Display the mean value
42+
self.result_label.config(text=f"Mean: {mean_value}")
43+
except Exception as e:
44+
# Display an error message if input is invalid
45+
self.result_label.config(text="Error: Invalid input")
46+
47+
def main():
48+
root = tk.Tk()
49+
app = NumPyTkinterApp(root)
50+
root.mainloop()
51+
52+
if __name__ == "__main__":
53+
main()

0 commit comments

Comments
 (0)