nummpyy 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nummpyy/__init__.py ADDED
@@ -0,0 +1,35 @@
1
+ import os
2
+ import sys
3
+
4
+ def show_codes(filename: str = None):
5
+ """
6
+ Displays code included in this package.
7
+ - If filename is given (without .py), shows that file's code.
8
+ - If no filename is given, shows all .py files.
9
+ """
10
+ base_path = os.path.dirname(__file__)
11
+ files = [f for f in os.listdir(base_path) if f.endswith(".py") and f != "__init__.py"]
12
+
13
+ if filename:
14
+ file_path = os.path.join(base_path, f"{filename}.py")
15
+ if os.path.exists(file_path):
16
+ print(f"\n=== Showing {filename}.py ===\n")
17
+ with open(file_path, "r", encoding="utf-8") as f:
18
+ print(f.read())
19
+ else:
20
+ print(f"\n❌ File '{filename}.py' not found in this package.\n")
21
+ print("Available files:")
22
+ for f in files:
23
+ print("•", f.replace(".py", ""))
24
+ else:
25
+ print("\nAll practical codes:\n")
26
+ for f in files:
27
+ print(f"\n=== {f} ===\n")
28
+ with open(os.path.join(base_path, f), "r", encoding="utf-8") as file:
29
+ print(file.read())
30
+
31
+
32
+ def main():
33
+ """Command-line entry point: nummpyy [filename]"""
34
+ filename = " ".join(sys.argv[1:]) or None
35
+ show_codes(filename)
@@ -0,0 +1,55 @@
1
+ import os
2
+ import numpy as np
3
+ import pandas as pd
4
+
5
+ try:
6
+ BASE = os.path.dirname(os.path.abspath(__file__))
7
+ except NameError:
8
+ BASE = os.getcwd()
9
+
10
+
11
+ def path(name):
12
+ return os.path.join(BASE, name)
13
+
14
+
15
+ def _fruit_df():
16
+ return pd.DataFrame(
17
+ [[10, np.nan, 30, 40],
18
+ [7, 14, 21, 28],
19
+ [55, np.nan, 8, 12],
20
+ [15, 14, np.nan, 8],
21
+ [7, 1, 1, np.nan],
22
+ [np.nan, 4, 9, 2]],
23
+ columns=["Apple", "Orange", "Banana", "Pear"],
24
+ index=["Basket1", "Basket2", "Basket3", "Basket4", "Basket5", "Basket6"])
25
+
26
+
27
+ def p6():
28
+ print("#################################")
29
+ print("THE ORIGINAL VALUES")
30
+ print(_fruit_df())
31
+
32
+ df = _fruit_df()
33
+ print("\nREPLACING THE VALUES WITH MEAN")
34
+ df.fillna(df.mean(), inplace=True)
35
+ print(df)
36
+
37
+ df = _fruit_df()
38
+ print("\nREPLACING THE VALUES WITH MEDIAN")
39
+ df.fillna(df.median(), inplace=True)
40
+ print(df)
41
+
42
+ df = _fruit_df()
43
+ print("\nREPLACING THE VALUES WITH MODE")
44
+ for column in df.columns:
45
+ df[column] = df[column].fillna(df[column].mode()[0])
46
+ print(df)
47
+
48
+ df = _fruit_df()
49
+ print("\nREPLACING THE VALUES WITH MINIMUM")
50
+ df.fillna(df.min(), inplace=True)
51
+ print(df)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ p6()
@@ -0,0 +1,30 @@
1
+ import os
2
+ import pandas as pd
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def load_ip_data():
15
+ df = pd.read_csv(path("IP_DATA_ALL.csv"), header=0, low_memory=False,
16
+ encoding="latin-1",
17
+ usecols=["Country", "Place.Name", "Latitude", "Longitude"])
18
+ df.rename(columns={"Place.Name": "Place_Name"}, inplace=True)
19
+ return df
20
+
21
+
22
+ def p2e():
23
+ IP_DATA_ALL = load_ip_data()
24
+ small = IP_DATA_ALL[["Country", "Place_Name", "Latitude"]]
25
+ AverageLatitude = small.groupby(["Country", "Place_Name"])["Latitude"].mean()
26
+ print(AverageLatitude)
27
+
28
+
29
+ if __name__ == "__main__":
30
+ p2e()
nummpyy/correlation.py ADDED
@@ -0,0 +1,43 @@
1
+ import os
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ try:
6
+ BASE = os.path.dirname(os.path.abspath(__file__))
7
+ except NameError:
8
+ BASE = os.getcwd()
9
+
10
+
11
+ def path(name):
12
+ return os.path.join(BASE, name)
13
+
14
+
15
+ def p14():
16
+ # If your files are real Excel files, change read_csv to read_excel
17
+ math = pd.read_csv(path("students_math.csv"))
18
+ science = pd.read_csv(path("student_science.csv"))
19
+
20
+ print("Math Dataset:")
21
+ print(math)
22
+ print("\nScience Dataset:")
23
+ print(science)
24
+
25
+ data = pd.merge(math, science, on="Student_ID")
26
+ print("\nMerged Dataset:")
27
+ print(data)
28
+
29
+ correlation = data["Math"].corr(data["Science"])
30
+ print("\nCorrelation between Math and Science =", round(correlation, 2))
31
+
32
+ print("\nCorrelation Matrix:")
33
+ print(data[["Math", "Science"]].corr())
34
+
35
+ plt.scatter(data["Math"], data["Science"])
36
+ plt.xlabel("Math Marks")
37
+ plt.ylabel("Science Marks")
38
+ plt.title("Correlation between Math and Science Marks")
39
+ plt.show()
40
+
41
+
42
+ if __name__ == "__main__":
43
+ p14()
nummpyy/datascience.py ADDED
@@ -0,0 +1,58 @@
1
+ import os
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ try:
6
+ BASE = os.path.dirname(os.path.abspath(__file__))
7
+ except NameError:
8
+ BASE = os.getcwd()
9
+
10
+
11
+ def path(name):
12
+ return os.path.join(BASE, name)
13
+
14
+
15
+ def p4():
16
+ # Histogram
17
+ y = [10, 5, 8, 4, 2]
18
+ plt.hist(y)
19
+ plt.title("Histogram")
20
+ plt.show()
21
+
22
+ # Pie chart (simple)
23
+ y = np.array([35, 25, 25, 15])
24
+ plt.pie(y)
25
+ plt.title("Pie Chart")
26
+ plt.show()
27
+
28
+ # Pie chart (labels, explode, shadow)
29
+ labels = ["apple", "banana", "cherry", "durian", "elderberries", "figs", "grapes"]
30
+ sizes = [32, 20, 15, 10, 10, 8, 5]
31
+ p = plt.pie(sizes, labels=labels, explode=(0.07, 0, 0, 0, 0, 0, 0),
32
+ autopct="%1.1f%%", startangle=130, shadow=True)
33
+ plt.axis("equal")
34
+ for text in p[1]:
35
+ text.set_fontsize(12)
36
+ plt.show()
37
+
38
+ # Line chart with grid
39
+ x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
40
+ y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
41
+ plt.title("Sports Watch Data")
42
+ plt.xlabel("Average Pulse")
43
+ plt.ylabel("Calorie Burnage")
44
+ plt.plot(x, y)
45
+ plt.grid()
46
+ plt.show()
47
+
48
+ # Stairs
49
+ y = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6, 3.0]
50
+ fig, ax = plt.subplots()
51
+ ax.stairs(y, linewidth=2.5)
52
+ ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
53
+ ylim=(0, 8), yticks=np.arange(1, 8))
54
+ plt.show()
55
+
56
+
57
+ if __name__ == "__main__":
58
+ p4()
nummpyy/edges.py ADDED
@@ -0,0 +1,36 @@
1
+ import os
2
+ import matplotlib.pyplot as plt
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def p10(image_name="1.png"):
15
+ from PIL import Image
16
+
17
+ imageIn = Image.open(path(image_name))
18
+ fig1 = plt.figure(figsize=(8, 8))
19
+ fig1.suptitle("Audi R8", fontsize=20)
20
+ plt.imshow(imageIn)
21
+ plt.show()
22
+
23
+ mask = imageIn.convert("L")
24
+ th = 49
25
+ imageOut = mask.point(lambda i: i < th and 255)
26
+ imageOut.save(path("audi.png"))
27
+
28
+ imageTest = Image.open(path("audi.png"))
29
+ fig2 = plt.figure(figsize=(8, 8))
30
+ fig2.suptitle("Audi R8 Edge", fontsize=20)
31
+ plt.imshow(imageTest, cmap="gray")
32
+ plt.show()
33
+
34
+
35
+ if __name__ == "__main__":
36
+ p10()
nummpyy/extraspaces.py ADDED
@@ -0,0 +1,21 @@
1
+ import os
2
+
3
+ try:
4
+ BASE = os.path.dirname(os.path.abspath(__file__))
5
+ except NameError:
6
+ BASE = os.getcwd()
7
+
8
+
9
+ def path(name):
10
+ return os.path.join(BASE, name)
11
+
12
+
13
+ def p2a():
14
+ baddata = " Data Science with too many spaces is great. "
15
+ print(">", baddata, "<")
16
+ cleandata = " ".join(baddata.split())
17
+ print(">", cleandata, "<")
18
+
19
+
20
+ if __name__ == "__main__":
21
+ p2a()
@@ -0,0 +1,39 @@
1
+ import os
2
+ import pandas as pd
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def load_ip_data():
15
+ df = pd.read_csv(path("IP_DATA_ALL.csv"), header=0, low_memory=False,
16
+ encoding="latin-1",
17
+ usecols=["Country", "Place.Name", "Latitude", "Longitude"])
18
+ df.rename(columns={"Place.Name": "Place_Name"}, inplace=True)
19
+ return df
20
+
21
+
22
+ def p2d():
23
+ IP_DATA_ALL = load_ip_data()
24
+ LondonData = IP_DATA_ALL.loc[IP_DATA_ALL["Place_Name"] == "London"]
25
+
26
+ LondonFree = LondonData[["Country", "Place_Name", "Latitude"]].copy()
27
+ print("Outliers (latitude outside 51.0 to 52.0)")
28
+ LondonOutliers = LondonFree[(LondonFree["Latitude"] < 51.0) |
29
+ (LondonFree["Latitude"] > 52.0)]
30
+ print(LondonOutliers)
31
+ print("Total outliers :", len(LondonOutliers))
32
+
33
+ print("\nNon-outliers (latitude inside 51.0 to 52.0)")
34
+ print(LondonFree[(LondonFree["Latitude"] >= 51.0) &
35
+ (LondonFree["Latitude"] <= 52.0)])
36
+
37
+
38
+ if __name__ == "__main__":
39
+ p2d()
nummpyy/histogram.py ADDED
@@ -0,0 +1,47 @@
1
+ import os
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+
6
+ try:
7
+ BASE = os.path.dirname(os.path.abspath(__file__))
8
+ except NameError:
9
+ BASE = os.getcwd()
10
+
11
+
12
+ def path(name):
13
+ return os.path.join(BASE, name)
14
+
15
+
16
+ def load_ip_data():
17
+ df = pd.read_csv(path("IP_DATA_ALL.csv"), header=0, low_memory=False,
18
+ encoding="latin-1",
19
+ usecols=["Country", "Place.Name", "Latitude", "Longitude"])
20
+ df.rename(columns={"Place.Name": "Place_Name"}, inplace=True)
21
+ return df
22
+
23
+
24
+ def p2f():
25
+ IP_DATA_ALL = load_ip_data()
26
+ x = IP_DATA_ALL["Latitude"].dropna()
27
+
28
+ mu, sigma = x.mean(), x.std()
29
+ print("Mean:", mu, " Std:", sigma)
30
+
31
+ num_bins = 25
32
+ fig, ax = plt.subplots(figsize=(10, 6))
33
+ n, bins, patches = ax.hist(x, num_bins, density=True, alpha=0.6)
34
+
35
+ # Normal distribution curve (computed with numpy)
36
+ y = (1 / (sigma * np.sqrt(2 * np.pi))) * np.exp(-0.5 * ((bins - mu) / sigma) ** 2)
37
+ ax.plot(bins, y, "--", color="red")
38
+
39
+ ax.set_xlabel("Latitude")
40
+ ax.set_ylabel("Probability density")
41
+ ax.set_title("Histogram of Latitude: mu=%.2f, sigma=%.2f" % (mu, sigma))
42
+ fig.tight_layout()
43
+ plt.show()
44
+
45
+
46
+ if __name__ == "__main__":
47
+ p2f()
nummpyy/horus.py ADDED
@@ -0,0 +1,36 @@
1
+ import os
2
+ import pandas as pd
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def p1b():
15
+ InputData = pd.read_csv(path("Country.csv"), encoding="latin-1")
16
+ print("Input Data Values")
17
+ print(InputData)
18
+ print("=" * 60)
19
+
20
+ ProcessData = InputData.copy()
21
+ ProcessData.drop(columns=["ISO-2-CODE", "ISO-3-Code"], inplace=True)
22
+ ProcessData.rename(columns={"Country": "CountryName",
23
+ "ISO-M49": "CountryNumber"}, inplace=True)
24
+ ProcessData.set_index("CountryNumber", inplace=True)
25
+ ProcessData.sort_values(by="CountryName", ascending=True, inplace=True)
26
+
27
+ print("Processed Data")
28
+ print(ProcessData)
29
+ print("=" * 60)
30
+
31
+ ProcessData.to_csv(path("HORUS-CSV-Country.csv"))
32
+ print("CSV to HORUS - Done Successfully")
33
+
34
+
35
+ if __name__ == "__main__":
36
+ p1b()
nummpyy/hough.py ADDED
@@ -0,0 +1,50 @@
1
+ import os
2
+ import numpy as np
3
+ import matplotlib.pyplot as plt
4
+
5
+ try:
6
+ BASE = os.path.dirname(os.path.abspath(__file__))
7
+ except NameError:
8
+ BASE = os.getcwd()
9
+
10
+
11
+ def path(name):
12
+ return os.path.join(BASE, name)
13
+
14
+
15
+ def p7(image_name="hough.jpg"):
16
+ import cv2
17
+
18
+ img = cv2.imread(path(image_name))
19
+ if img is None:
20
+ print("Could not read", image_name, "- put it in the same folder.")
21
+ return
22
+
23
+ plt.figure(figsize=(8, 6))
24
+ plt.title("Original Image")
25
+ plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
26
+ plt.axis("off")
27
+ plt.show()
28
+
29
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
30
+ edges = cv2.Canny(gray, 50, 200)
31
+
32
+ lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 68,
33
+ minLineLength=15, maxLineGap=250)
34
+
35
+ if lines is not None:
36
+ for line in lines:
37
+ x1, y1, x2, y2 = line.flatten()
38
+ cv2.line(img, (x1, y1), (x2, y2), (255, 0, 0), 3)
39
+ else:
40
+ print("No lines detected.")
41
+
42
+ plt.figure(figsize=(8, 6))
43
+ plt.title("Line Detection using Hough Transform")
44
+ plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
45
+ plt.axis("off")
46
+ plt.show()
47
+
48
+
49
+ if __name__ == "__main__":
50
+ p7()
@@ -0,0 +1,36 @@
1
+ import os
2
+ import matplotlib.pyplot as plt
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def p9(image_name="1.png"):
15
+ import matplotlib.image as mpimg
16
+
17
+ img = mpimg.imread(path(image_name))
18
+ print("Size:", img.shape)
19
+
20
+ t = 1
21
+ plt.figure(figsize=(8, 8))
22
+ plt.title("(" + str(t) + ") Original")
23
+ plt.imshow(img)
24
+ plt.show()
25
+
26
+ if img.ndim == 3:
27
+ for c in range(img.shape[2]):
28
+ t += 1
29
+ plt.figure(figsize=(8, 8))
30
+ plt.title("(" + str(t) + ") Channel: " + str(c))
31
+ plt.imshow(img[:, :, c])
32
+ plt.show()
33
+
34
+
35
+ if __name__ == "__main__":
36
+ p9()
nummpyy/nlp.py ADDED
@@ -0,0 +1,49 @@
1
+ import os
2
+
3
+ try:
4
+ BASE = os.path.dirname(os.path.abspath(__file__))
5
+ except NameError:
6
+ BASE = os.getcwd()
7
+
8
+
9
+ def path(name):
10
+ return os.path.join(BASE, name)
11
+
12
+
13
+ def p8():
14
+ import nltk
15
+ nltk.download("punkt")
16
+ nltk.download("punkt_tab")
17
+ nltk.download("stopwords")
18
+
19
+ from nltk.tokenize import sent_tokenize, word_tokenize
20
+ from nltk.corpus import stopwords
21
+ from nltk.probability import FreqDist
22
+
23
+ text = """
24
+ Natural Language Processing (NLP) is a field of Artificial Intelligence.
25
+ It focuses on the interaction between computers and human language.
26
+ NLP helps machines understand, interpret, and generate human language.
27
+ """
28
+
29
+ print("Sentence Tokenization:")
30
+ print(sent_tokenize(text), "\n")
31
+
32
+ print("Word Tokenization:")
33
+ words = word_tokenize(text)
34
+ print(words, "\n")
35
+
36
+ print("Removing Stopwords:")
37
+ stop_words = set(stopwords.words("english"))
38
+ filtered_words = [w for w in words
39
+ if w.lower() not in stop_words and w.isalnum()]
40
+ print(filtered_words, "\n")
41
+
42
+ print("Frequency Distribution:")
43
+ fdist = FreqDist(filtered_words)
44
+ for word, freq in fdist.most_common():
45
+ print(f"{word}: {freq}")
46
+
47
+
48
+ if __name__ == "__main__":
49
+ p8()
@@ -0,0 +1,25 @@
1
+ import os
2
+ import datetime
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def p2c():
15
+ baddate = datetime.date(2019, 10, 31)
16
+ baddata = format(baddate, "%Y-%m-%d")
17
+ gooddate = datetime.datetime.strptime(baddata, "%Y-%m-%d")
18
+ gooddata = format(gooddate, "%d %B %Y")
19
+
20
+ print("Bad Date :", baddata)
21
+ print("Good Date :", gooddata)
22
+
23
+
24
+ if __name__ == "__main__":
25
+ p2c()
nummpyy/removing.py ADDED
@@ -0,0 +1,22 @@
1
+ import os
2
+ import string
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def p2b():
15
+ baddata = "Data\x00Science with\x02 funny characters is\x10 great"
16
+ print("Bad data :", repr(baddata))
17
+ cleandata = "".join(filter(lambda x: x in string.printable, baddata))
18
+ print("Clean data:", repr(cleandata))
19
+
20
+
21
+ if __name__ == "__main__":
22
+ p2b()
@@ -0,0 +1,37 @@
1
+ import os
2
+ import pandas as pd
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def load_ip_data():
15
+ df = pd.read_csv(path("IP_DATA_ALL.csv"), header=0, low_memory=False,
16
+ encoding="latin-1",
17
+ usecols=["Country", "Place.Name", "Latitude", "Longitude"])
18
+ df.rename(columns={"Place.Name": "Place_Name"}, inplace=True)
19
+ return df
20
+
21
+
22
+ def p3():
23
+ sFileName = path("IP_DATA_ALL.csv")
24
+ print("Loading :", sFileName)
25
+ IP_DATA_ALL = load_ip_data()
26
+
27
+ ROUTERLOC = IP_DATA_ALL.drop_duplicates(subset=None, keep="first",
28
+ inplace=False)
29
+ print("Rows :", ROUTERLOC.shape[0])
30
+ print("Columns :", ROUTERLOC.shape[1])
31
+
32
+ ROUTERLOC.to_csv(path("Retrieve_Router_Location.csv"), index=False)
33
+ print("### Done!! ############################################")
34
+
35
+
36
+ if __name__ == "__main__":
37
+ p3()
nummpyy/structured.py ADDED
@@ -0,0 +1,58 @@
1
+ import os
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+
6
+ # Fallback to current working directory in interactive environments (like Colab) where __file__ is not defined
7
+ try:
8
+ BASE = os.path.dirname(os.path.abspath(__file__))
9
+ except NameError:
10
+ BASE = os.getcwd()
11
+
12
+
13
+ def path(name):
14
+ return os.path.join(BASE, name)
15
+
16
+
17
+ def p1a(image_name="1.png"):
18
+ from skimage import io
19
+
20
+ # Checking if the path exists, falling back to direct string if not absolute
21
+ img_path = path(image_name) if not os.path.isabs(image_name) else image_name
22
+ image = io.imread(img_path)
23
+ plt.imshow(image)
24
+ plt.title("Input Image")
25
+ plt.axis("off")
26
+ plt.show()
27
+
28
+ print("Image Shape :", image.shape)
29
+ print("Height :", image.shape[0])
30
+ print("Width :", image.shape[1])
31
+
32
+ if image.ndim == 2: # grayscale -> make 3 channels
33
+ image = np.stack([image] * 3, axis=-1)
34
+
35
+ height, width, channels = image.shape
36
+ print("Color Mode :", "RGB" if channels == 3 else "RGBA")
37
+
38
+ ys, xs = np.indices((height, width))
39
+ r = image[:, :, 0].ravel()
40
+ g = image[:, :, 1].ravel()
41
+ b = image[:, :, 2].ravel()
42
+ a = image[:, :, 3].ravel() if channels == 4 else np.full(r.shape, 255)
43
+
44
+ df = pd.DataFrame({
45
+ "X": xs.ravel(), "Y": ys.ravel(),
46
+ "Red": r, "Green": g, "Blue": b, "Alpha": a
47
+ })
48
+
49
+ print(df.head(10))
50
+ print("\nRows :", df.shape[0])
51
+ print("Columns :", df.shape[1])
52
+
53
+ df.to_csv(path("Image_to_HORUS.csv"), index=False)
54
+ print("\nCSV File Saved Successfully.")
55
+
56
+
57
+ if __name__ == "__main__":
58
+ p1a()
nummpyy/supervised.py ADDED
@@ -0,0 +1,68 @@
1
+ import os
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ try:
6
+ BASE = os.path.dirname(os.path.abspath(__file__))
7
+ except NameError:
8
+ BASE = os.getcwd()
9
+
10
+
11
+ def path(name):
12
+ return os.path.join(BASE, name)
13
+
14
+
15
+ def p12():
16
+ from sklearn.datasets import fetch_california_housing
17
+ from sklearn.model_selection import train_test_split
18
+ from sklearn.linear_model import LinearRegression
19
+ from sklearn.metrics import mean_squared_error, r2_score
20
+
21
+ try:
22
+ data = fetch_california_housing() # needs internet the first time
23
+ X = pd.DataFrame(data.data, columns=data.feature_names)
24
+ y = data.target
25
+ except Exception:
26
+ # Offline fallback: use the dummy housing file next to this script
27
+ print("(No internet - using dummy_housing.csv instead)")
28
+ d = pd.read_csv(path("dummy_housing.csv"))
29
+ y = d["Price"].values
30
+ X = d.drop(columns=["Price"])
31
+
32
+ print("Dataset shape:", X.shape)
33
+ print("Features:", list(X.columns))
34
+
35
+ X_train, X_test, y_train, y_test = train_test_split(
36
+ X, y, test_size=0.2, random_state=42)
37
+ print("\nTraining samples:", X_train.shape[0])
38
+ print("Testing samples:", X_test.shape[0])
39
+
40
+ model = LinearRegression()
41
+ model.fit(X_train, y_train)
42
+ y_pred = model.predict(X_test)
43
+
44
+ print("\n========== Model Evaluation ==========")
45
+ print("Mean Squared Error (MSE):", mean_squared_error(y_test, y_pred))
46
+ print("R² Score:", r2_score(y_test, y_pred))
47
+
48
+ comparison = pd.DataFrame({"Actual Price": y_test,
49
+ "Predicted Price": y_pred})
50
+ print("\n========== Actual vs Predicted ==========")
51
+ print(comparison.head(10))
52
+
53
+ plt.figure(figsize=(8, 6))
54
+ plt.scatter(y_test, y_pred, alpha=0.5)
55
+ lo = min(y_test.min(), y_pred.min())
56
+ hi = max(y_test.max(), y_pred.max())
57
+ plt.plot([lo, hi], [lo, hi], color="red", linewidth=2,
58
+ label="Perfect Prediction")
59
+ plt.xlabel("Actual Price")
60
+ plt.ylabel("Predicted Price")
61
+ plt.title("Actual vs Predicted Median House Values")
62
+ plt.legend()
63
+ plt.grid(True)
64
+ plt.show()
65
+
66
+
67
+ if __name__ == "__main__":
68
+ p12()
nummpyy/thumbnail.py ADDED
@@ -0,0 +1,41 @@
1
+ import os
2
+ import matplotlib.pyplot as plt
3
+
4
+ try:
5
+ BASE = os.path.dirname(os.path.abspath(__file__))
6
+ except NameError:
7
+ BASE = os.getcwd()
8
+
9
+
10
+ def path(name):
11
+ return os.path.join(BASE, name)
12
+
13
+
14
+ def p11(image_name="1.png"):
15
+ from PIL import Image
16
+
17
+ nSize = 4
18
+ img = Image.open(path(image_name))
19
+
20
+ plt.figure(figsize=(nSize, nSize))
21
+ plt.title("Unchanged")
22
+ plt.imshow(img)
23
+ plt.show()
24
+
25
+ img.thumbnail((64, 64), Image.Resampling.LANCZOS) # resizes in place
26
+
27
+ plt.figure(figsize=(nSize, nSize))
28
+ plt.title("Resized")
29
+ plt.imshow(img)
30
+ plt.show()
31
+
32
+ plt.figure(figsize=(nSize, nSize))
33
+ plt.title("Resized with Bi-Cubic")
34
+ plt.imshow(img, interpolation="bicubic")
35
+ plt.show()
36
+
37
+ print("### Done!! ###############################################")
38
+
39
+
40
+ if __name__ == "__main__":
41
+ p11()
@@ -0,0 +1,109 @@
1
+ import os
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+
6
+ try:
7
+ BASE = os.path.dirname(os.path.abspath(__file__))
8
+ except NameError:
9
+ BASE = os.getcwd()
10
+
11
+
12
+ def path(name):
13
+ return os.path.join(BASE, name)
14
+
15
+
16
+ def p13():
17
+ import seaborn as sns
18
+ from sklearn.datasets import load_iris
19
+ from sklearn.preprocessing import StandardScaler
20
+ from sklearn.decomposition import PCA
21
+ from sklearn.cluster import KMeans
22
+ from sklearn.metrics import (adjusted_rand_score, silhouette_score,
23
+ confusion_matrix)
24
+
25
+ iris = load_iris()
26
+ X = pd.DataFrame(iris.data, columns=iris.feature_names)
27
+ y_true = iris.target
28
+ label_names = iris.target_names
29
+
30
+ print("Shape of feature data:", X.shape)
31
+ print(X.describe())
32
+
33
+ df_viz = X.copy()
34
+ df_viz["species"] = [label_names[i] for i in y_true]
35
+ sns.pairplot(df_viz, hue="species")
36
+ plt.show()
37
+
38
+ X_scaled = StandardScaler().fit_transform(X)
39
+
40
+ # Elbow method
41
+ inertia_values = []
42
+ k_range = range(1, 10)
43
+ for k in k_range:
44
+ km = KMeans(n_clusters=k, random_state=42, n_init=10)
45
+ km.fit(X_scaled)
46
+ inertia_values.append(km.inertia_)
47
+
48
+ plt.figure(figsize=(8, 5))
49
+ plt.plot(k_range, inertia_values, marker="o")
50
+ plt.xlabel("Number of Clusters (K)")
51
+ plt.ylabel("Inertia")
52
+ plt.title("Elbow Method to Find Optimal K")
53
+ plt.show()
54
+
55
+ # K-Means with K = 3
56
+ kmeans = KMeans(n_clusters=3, random_state=42, n_init=10)
57
+ cluster_labels = kmeans.fit_predict(X_scaled)
58
+
59
+ X["predicted_cluster"] = cluster_labels
60
+ X["actual_species"] = [label_names[i] for i in y_true]
61
+
62
+ # Map cluster numbers to real labels
63
+ mapping = {}
64
+ for cluster in np.unique(cluster_labels):
65
+ mask = cluster_labels == cluster
66
+ mapping[cluster] = pd.Series(y_true[mask]).mode()[0]
67
+
68
+ predicted_labels = np.array([mapping[c] for c in cluster_labels])
69
+ X["predicted_label_name"] = [label_names[i] for i in predicted_labels]
70
+ print(X[["actual_species", "predicted_cluster",
71
+ "predicted_label_name"]].head(10))
72
+
73
+ accuracy = (predicted_labels == y_true).mean()
74
+ print(f"Clustering-based label prediction accuracy: {accuracy * 100:.2f}%")
75
+ print(f"Adjusted Rand Index: {adjusted_rand_score(y_true, cluster_labels):.3f}")
76
+ print(f"Silhouette Score: {silhouette_score(X_scaled, cluster_labels):.3f}")
77
+
78
+ # Confusion matrix
79
+ cm = confusion_matrix(y_true, predicted_labels)
80
+ plt.figure(figsize=(6, 5))
81
+ sns.heatmap(cm, annot=True, fmt="d", cmap="Blues",
82
+ xticklabels=label_names, yticklabels=label_names)
83
+ plt.xlabel("Predicted Label (from clustering)")
84
+ plt.ylabel("Actual Label")
85
+ plt.title("Confusion Matrix: Clustering vs True Labels")
86
+ plt.show()
87
+
88
+ # PCA visualisation
89
+ X_pca = PCA(n_components=2).fit_transform(X_scaled)
90
+ plt.figure(figsize=(12, 5))
91
+
92
+ plt.subplot(1, 2, 1)
93
+ plt.scatter(X_pca[:, 0], X_pca[:, 1], c=cluster_labels, cmap="viridis")
94
+ plt.title("Predicted Clusters (K-Means)")
95
+ plt.xlabel("PCA Component 1")
96
+ plt.ylabel("PCA Component 2")
97
+
98
+ plt.subplot(1, 2, 2)
99
+ plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y_true, cmap="viridis")
100
+ plt.title("Actual Species (Ground Truth)")
101
+ plt.xlabel("PCA Component 1")
102
+ plt.ylabel("PCA Component 2")
103
+
104
+ plt.tight_layout()
105
+ plt.show()
106
+
107
+
108
+ if __name__ == "__main__":
109
+ p13()
@@ -0,0 +1,86 @@
1
+ import os
2
+ import numpy as np
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+
6
+ try:
7
+ BASE = os.path.dirname(os.path.abspath(__file__))
8
+ except NameError:
9
+ BASE = os.getcwd()
10
+
11
+
12
+ def path(name):
13
+ return os.path.join(BASE, name)
14
+
15
+
16
+ def p5():
17
+ import matplotlib as ml
18
+ from pandas.plotting import (scatter_matrix, parallel_coordinates,
19
+ autocorrelation_plot)
20
+
21
+ # ---- Area plot ----
22
+ turnover = [2, 7, 14, 17, 20, 27, 30, 38, 25, 18, 6, 1]
23
+ plt.fill_between(np.arange(12), turnover, color="skyblue", alpha=0.4)
24
+ plt.plot(np.arange(12), turnover, color="Slateblue", alpha=0.6, linewidth=2)
25
+ plt.tick_params(labelsize=12)
26
+ plt.xticks(np.arange(12), np.arange(1, 13))
27
+ plt.xlabel("Month", size=12)
28
+ plt.ylabel("Turnover (K euros) of ice-cream", size=12)
29
+ plt.ylim(bottom=0)
30
+ plt.show()
31
+
32
+ # ---- Scatter plot ----
33
+ x = range(-10, 38, 1)
34
+ y = np.array(range(60, 770, 15)) + np.random.randn(48) * 40
35
+ plt.scatter(x, y, s=200, alpha=0.6)
36
+ plt.xlabel("Temperature (°C)", size=12)
37
+ plt.ylabel("Volume per store", size=12)
38
+ plt.show()
39
+
40
+ ml.style.use("ggplot")
41
+
42
+ # ---- KDE ----
43
+ plt.figure(figsize=(10, 10))
44
+ ser = pd.Series(np.random.randn(1000))
45
+ ser.plot(figsize=(10, 10), kind="kde")
46
+ plt.savefig(path("kde.png"), dpi=600)
47
+ plt.tight_layout()
48
+ plt.show()
49
+
50
+ # ---- Scatter matrix ----
51
+ df = pd.DataFrame(np.random.randn(1000, 5),
52
+ columns=["Y2014", "Y2015", "Y2016", "Y2017", "Y2018"])
53
+ scatter_matrix(df, alpha=0.2, figsize=(10, 10), diagonal="kde")
54
+ plt.savefig(path("scatter_matrix.png"), dpi=600)
55
+ plt.tight_layout()
56
+ plt.show()
57
+
58
+ # ---- Parallel coordinates (iris1.csv, else built-in iris) ----
59
+ plt.figure(figsize=(10, 10))
60
+ if os.path.exists(path("iris1.csv")):
61
+ data = pd.read_csv(path("iris1.csv"))
62
+ else:
63
+ from sklearn.datasets import load_iris
64
+ iris = load_iris()
65
+ data = pd.DataFrame(iris.data, columns=["SepalLength", "SepalWidth",
66
+ "PetalLength", "PetalWidth"])
67
+ data["Name"] = [iris.target_names[i] for i in iris.target]
68
+ parallel_coordinates(data, "Name")
69
+ plt.savefig(path("parallel_coordinates.png"), dpi=600)
70
+ plt.tight_layout()
71
+ plt.show()
72
+
73
+ # ---- Autocorrelation plot ----
74
+ plt.figure(figsize=(10, 10))
75
+ data = pd.Series(0.7 * np.random.rand(1000) +
76
+ 0.3 * np.sin(np.linspace(-9 * np.pi, 9 * np.pi, num=1000)))
77
+ autocorrelation_plot(data)
78
+ plt.savefig(path("autocorrelation_plot.png"), dpi=600)
79
+ plt.tight_layout()
80
+ plt.show()
81
+
82
+ ml.style.use("default")
83
+
84
+
85
+ if __name__ == "__main__":
86
+ p5()
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: nummpyy
3
+ Version: 1.0.0
4
+ Summary: Data Science practical programs, printable from Python or the terminal
5
+ Home-page:
6
+ Author: andhrew
7
+ Author-email: xyz@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: license
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ # nummpyy
25
+
26
+ A Python package that stores **Data Science** practical programs and prints their source code on demand, from Python or the terminal.
27
+
28
+ Install it once with `pip`, then view any practical on any machine without copying files around.
29
+
30
+ ---
31
+
32
+ ## Practicals included
33
+
34
+ Pass any of these names (without `.py`) to `show_codes()` or the `nummpyy` command:
35
+
36
+ | | | |
37
+ |---|---|---|
38
+ | `assesssuperstep` | `averagelatitude` | `correlation` |
39
+ | `datascience` | `edges` | `extraspaces` |
40
+ | `fixedlatitude` | `histogram` | `horus` |
41
+ | `hough` | `multichannel` | `nlp` |
42
+ | `reformatting` | `removing` | `retrievesuperstep` |
43
+ | `structured` | `supervised` | `thumbnail` |
44
+ | `unsupervised` | `visualization` | |
45
+
46
+ The programs use `numpy`, `pandas` and `matplotlib`. Install those yourself if you want to run them; `nummpyy` only prints them.
47
+
48
+ ---
49
+
50
+ ## Install
51
+
52
+ ```bash
53
+ pip install nummpyy
54
+ ```
55
+
56
+ Upgrade:
57
+
58
+ ```bash
59
+ pip install --upgrade nummpyy
60
+ ```
61
+
62
+ Requires Python 3.6 or newer.
63
+
64
+ ---
65
+
66
+ ## View the programs
67
+
68
+ ### From the terminal
69
+
70
+ ```bash
71
+ nummpyy # show all practicals
72
+ nummpyy correlation # show one practical
73
+ ```
74
+
75
+ ### From Python
76
+
77
+ ```python
78
+ import nummpyy
79
+
80
+ nummpyy.show_codes() # show all practicals
81
+ nummpyy.show_codes("correlation") # show one practical
82
+ ```
83
+
84
+ ### In Google Colab or Jupyter
85
+
86
+ ```python
87
+ !pip install nummpyy
88
+ import nummpyy
89
+ nummpyy.show_codes("hough")
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Publishing a new version (for maintainers)
95
+
96
+ 1. Add or update files in the `nummpyy/` folder.
97
+ 2. Increase `version` in `setup.py` (e.g. `1.0.1`). PyPI never accepts the same version twice.
98
+ 3. Clean old builds:
99
+ ```bash
100
+ rm -rf dist build *.egg-info
101
+ ```
102
+ 4. Build:
103
+ ```bash
104
+ python3 -m build
105
+ ```
106
+ 5. Upload to PyPI (username `__token__`, password is your `pypi-...` API token):
107
+ ```bash
108
+ python3 -m twine upload dist/*
109
+ ```
110
+
111
+ ---
112
+
113
+ ## License
114
+
115
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,27 @@
1
+ nummpyy/__init__.py,sha256=8G7C5aWV0Em38f0Mhaqwg-9n-zRlIS43r6OxNOC-zCA,1219
2
+ nummpyy/assesssuperstep.py,sha256=40hrOqQRWdsMHRkBylQlr86ZHvTZYYgPc6Tybik5AQg,1254
3
+ nummpyy/averagelatitude.py,sha256=GcrmunEJETzppEnDnTcUvxR08w2wQA1I0zvA-PkHVEg,740
4
+ nummpyy/correlation.py,sha256=DfK2QZMXTOdUwnA8v0WcocpI83zq162RNl6s-ruf45Y,1035
5
+ nummpyy/datascience.py,sha256=2FcXUDjfSbyB2rh82zOyKy3syxAF5SiUVZtQEY2pd3M,1424
6
+ nummpyy/edges.py,sha256=sl05Uzxivd3r9wjAyz1NUUzo7AlPiGKr_3ueGkpZA2I,774
7
+ nummpyy/extraspaces.py,sha256=rTPIaxgDrqx_1zG-aVRl0CuUNDhqZ7Mm-NfR_OVjhb8,395
8
+ nummpyy/fixedlatitude.py,sha256=Mcoffh2T3Jmdpx0GKQOrTxsjWvbCgp6L9v1KYWRz1Gw,1148
9
+ nummpyy/histogram.py,sha256=r7L0LV6lnA0wEqUYtMCO-XllC_j6K7gRfLKWkb3-mNg,1235
10
+ nummpyy/horus.py,sha256=FYtrVufWafX0NM-AYHvTdkvYn0PWF2ljVDgkwvyArl0,926
11
+ nummpyy/hough.py,sha256=IDzSQEw1yDabOq_qIgy6-4_yhm8etqqSVIfWxUsfgWg,1191
12
+ nummpyy/multichannel.py,sha256=TBpIP353328ITBSwcbd8D7s4XbfDYbD01JfJgJqa_Vw,734
13
+ nummpyy/nlp.py,sha256=BUxp2gywXiIfNPRMd7Q1nqOlJrQk239qop0pICH0A9A,1244
14
+ nummpyy/reformatting.py,sha256=27t2MGcNXX8C-O3R0zLxP3VFOc2wHxQMRyaa1MY8gKA,493
15
+ nummpyy/removing.py,sha256=0QUfnW2fcyhMB1BrcJx1yzSPpk-0dQGwxz4NNFX27z4,457
16
+ nummpyy/retrievesuperstep.py,sha256=RUyoOVibz0p3Z2IIdGMJ8cCnAqnzntP68ivqXtvh4AQ,995
17
+ nummpyy/structured.py,sha256=cIe7pF5GQl3V2OIhub2pRnNkY7cJ2SGGDf3o0mJvitI,1580
18
+ nummpyy/supervised.py,sha256=o5Az8glQfn2932OpzzmIj_iC4jaNZVClI4FWdnjBrVc,2145
19
+ nummpyy/thumbnail.py,sha256=xjWF-0MgVwwP0HEolpIEfMMzUGoEOzrekY631DAGGNY,836
20
+ nummpyy/unsupervised.py,sha256=t9zMAGW2SgpGoSboVxVlxdqJYcyuBsY8T9qzFVVg8JE,3406
21
+ nummpyy/visualization.py,sha256=FuPhep7BsGGrabiOhs9Bgq2Py7zCviaXtzS7ncmJvuU,2714
22
+ nummpyy-1.0.0.dist-info/licenses/LICENSE,sha256=ZjOKHf0c1nYfvWea8C8w5Qxx-X-H4hBacrIZ_JDORRo,1075
23
+ nummpyy-1.0.0.dist-info/METADATA,sha256=7-JgEnFx6HhQjAmWDvSmBlM1qYjOySDxPZUVO-GdvV4,2461
24
+ nummpyy-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
25
+ nummpyy-1.0.0.dist-info/entry_points.txt,sha256=JGkVpI0VJ-6bn47AlOw1yDxOm5K5XigJjXtmiJBan5U,41
26
+ nummpyy-1.0.0.dist-info/top_level.txt,sha256=7_s1FxniaU1yVUuwBNIm4j4HL1WUaIhJ-8vtjqIt48Q,8
27
+ nummpyy-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ nummpyy = nummpyy:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Chirag Vishwakarma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ nummpyy