Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Test/P01_Introduction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Author: OMKAR PATHAK

# NumPy (Numeric Python) is a Python package used for building multi dimensional arrays and performing
# various operations

# In this program we will walk through various concepts and see available functions in the NumPy package.

# For installing: pip3 install numpy

import numpy as np

# we have a function arange() which makes an array of the specified dimension. Example:
myArray = np.arange(20)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Non-Standard Variable Naming (camelCase in Python)

In Python, variable names should follow the snake_case convention. Additionally, 'myArray' is a generic name; consider using a more descriptive name like numbers_array or sequence_array to improve clarity.

Suggested change
myArray = np.arange(20)
numbers_array = np.arange(20)
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) strictly recommend snake_case for variables
  2. The prefix 'my' is redundant and adds no semantic value to the variable purpose
  3. Descriptive names like 'numbers_array' better communicate the data structure content

Gaps

  1. The variable name is used in an educational/tutorial context where generic names are common
  2. camelCase is technically functional in Python but violates PEP 8 style standards

print(myArray) # [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19]

# an array from 10 to 20
myArray = np.arange(10, 20) # [10 11 12 13 14 15 16 17 18 19]
print(myArray)

# an array from 10 to 20 with 2 steps
myArray = np.arange(10, 20, 2)
print(myArray) # [10 12 14 16 18]

# reshape() helps to reshape our NumPy array
myArray = np.arange(20)
# syntax: reshape(number_of_rows, number_of_columns)
myArray = myArray.reshape(4, 5)
print(myArray)

# [[ 0  1  2  3  4]
#  [ 5  6  7  8  9]
#  [10 11 12 13 14]
#  [15 16 17 18 19]]

myArray = myArray.reshape(10, 2)
print(myArray)

# [[ 0  1]
#  [ 2  3]
#  [ 4  5]
#  [ 6  7]
#  [ 8  9]
#  [10 11]
#  [12 13]
#  [14 15]
#  [16 17]
#  [18 19]]

# shape returns the shape of the array. The length of shape tuple is called as rank (or dimension)
print(myArray.shape) # (10, 2)

# ndim returns the dimension (rank) of the array
print(myArray.ndim) # 2

# size returns the total number of elements in the array
print(myArray.size) # 20

# to check the data we have dtype.
print(myArray.dtype) # int64

# zeros creates an array will all zeros
myArray = np.zeros((3, 4))
print(myArray)

# [[ 0.  0.  0.  0.]
#  [ 0.  0.  0.  0.]
#  [ 0.  0.  0.  0.]]

# ones creates an array with all ones
myArray = np.ones((3, 4))
print(myArray)

# [[ 1.  1.  1.  1.]
#  [ 1.  1.  1.  1.]
#  [ 1.  1.  1.  1.]]

# numpy random module helps to initialize array with random values
myArray = np.random.rand(3, 4)
print(myArray)

# [[ 0.54808903  0.08750717  0.23886267  0.93589283]
#  [ 0.90750146  0.31197039  0.54013725  0.91092763]
#  [ 0.38827674  0.04647878  0.15997665  0.94909537]]
34 changes: 34 additions & 0 deletions Test/P02_NumpyDataTypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Author: OMKAR PATHAK

# Data type Description
# bool_ Boolean (True or False) stored as a byte
# int_ Default integer type (same as C long; normally either int64 or int32)
# intc Identical to C int (normally int32 or int64)
# intp Integer used for indexing (same as C ssize_t; normally either int32 or int64)
# int8 Byte (-128 to 127)
# int16 Integer (-32768 to 32767)
# int32 Integer (-2147483648 to 2147483647)
# int64 Integer (-9223372036854775808 to 9223372036854775807)
# uint8 Unsigned integer (0 to 255)
# uint16 Unsigned integer (0 to 65535)
# uint32 Unsigned integer (0 to 4294967295)
# uint64 Unsigned integer (0 to 18446744073709551615)
# float_ Shorthand for float64.
# float16 Half precision float: sign bit, 5 bits exponent, 10 bits mantissa
# float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa
# float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa
# complex_ Shorthand for complex128.
# complex64 Complex number, represented by two 32-bit floats (real and imaginary components)
# complex128 Complex number, represented by two 64-bit floats (real and imaginary components)

import numpy as np

# while creating a numpy array, any data type from above can be explicitly specified.
myArray = np.arange(10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Variable Naming Improvement

The variable name myArray uses camelCase, which is inconsistent with Python's snake_case convention. Additionally, myArray is partially generic; a more descriptive name like sequence_array or numbers_array would improve clarity.

Suggested change
myArray = np.arange(10)
numbers_array = np.arange(10)
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) recommend snake_case for variable names
  2. Descriptive names like 'numbers_array' convey the purpose better than 'myArray'
  3. Consistency in naming style reduces cognitive load during code reviews

Gaps

  1. The term 'myArray' is common in educational snippets or quick scripts
  2. Small script scope makes the generic nature of the name less impactful

print(myArray) # [0 1 2 3 4 5 6 7 8 9]

myArray = np.array(myArray, dtype = np.float32)
print(myArray) # [ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9.]

myArray = np.array(myArray, dtype = np.complex64)
print(myArray) # [ 0.+0.j  1.+0.j  2.+0.j  3.+0.j  4.+0.j  5.+0.j  6.+0.j  7.+0.j  8.+0.j 9.+0.j]
24 changes: 24 additions & 0 deletions Test/P03_NumpyAttributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Author: OMKAR PATHAK

# These are the various attributes provided by NumPy.

import numpy as np

myArray = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Variable Naming Convention Violation

The variable name 'myArray' uses camelCase, which violates the Python snake_case naming convention. Additionally, 'my' is a generic prefix that adds no descriptive value to the variable's purpose.

Suggested change
myArray = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require snake_case for variable names.
  2. The prefix 'my' is considered a forbidden generic/redundant naming pattern.
  3. Using descriptive names like 'matrix' or 'data_grid' improves code maintainability.

Gaps

  1. The term 'array' is a technical term, but the 'my' prefix is discouraged in most enterprise standards.
  2. Project-specific conventions might allow camelCase, though it deviates from PEP 8.

print(myArray)

# [[1 2 3]
#  [4 5 6]
#  [7 8 9]]

# ndarray.size returns the number of items in the array
print(myArray.size) # 9

# ndarray.shape returns a tuple consisting of array dimensions
print(myArray.shape) # (3, 3)

# ndarray.ndim returns the number of array dimensions
print(myArray.ndim) # 2

# ndarray.itemsize returns the memory size of each element in the array
print(myArray.itemsize) # 8
43 changes: 43 additions & 0 deletions Test/P04_ArrayFromNumericalRanges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Author: OMKAR PATHAK

# This program illustrates how to create an adarray from numerical ranges

import numpy as np

# ndarray.arange(start, stop, step, dtype)
# Creates a numpy array from 1 to 20
myArray = np.arange(1, 21)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Non-Standard Abbreviation in Variable Name

The variable name 'myArray' uses the 'my' prefix and 'Array' suffix which are considered generic. A more descriptive name like 'numerical_range' or 'sequence_array' would better reflect the data's purpose.

Suggested change
myArray = np.arange(1, 21)
numerical_range = np.arange(1, 21)
Reasons & Gaps

Reasons

  1. The 'my' prefix is a generic filler that adds no semantic value to the variable name
  2. Using 'Array' as a suffix is redundant when the type is obvious from the assignment
  3. Descriptive names like 'numerical_range' improve code maintainability and intent clarity

Gaps

  1. 'myArray' is a very common naming pattern in educational or tutorial-style code snippets
  2. The variable is functional and its type is clear from the context of the NumPy call

print(myArray) # [ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20]

# Specifying data type of each element
myArray = np.arange(10, dtype = 'float')
print(myArray) # [ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9.]

# Specifying steps to jump in between two elements
myArray = np.arange(1, 21, 2)
print(myArray) # [ 1  3  5  7  9 11 13 15 17 19]

# ndarray.linspace(start, stop, num, endpoint, retstep, dtype)
# Shows 5 equal intervals between 10 to 20
myArray = np.linspace(10, 20, 5)
print(myArray) # [ 10.   12.5  15.   17.5  20. ]

# if endpoint is set to false the last number inn STOP parameter is not executed
myArray = np.linspace(10, 20, 5, endpoint = False)
print(myArray) # [ 10.  12.  14.  16.  18.]

# ndarray.lopspace returns an ndarray object that contains the numbers that are evenly spaced
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 100%

JAS - Just a suggestion
Typo in Function Name in Comment

I noticed a small typo in the comment describing the logspace function. It's currently written as lopspace, which might be confusing for someone trying to learn the API. Let's correct it to logspace to match the actual NumPy function name.

Suggested change
# ndarray.lopspace returns an ndarray object that contains the numbers that are evenly spaced
# ndarray.logspace returns an ndarray object that contains the numbers that are evenly spaced

# on a log scale.
# ndarray.logscale(start, stop, num, endpoint, base, dtype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 100%

JAS - Just a suggestion
Incorrect Function Name in Comment

In the comment on line 31, the function is referred to as ndarray.logscale. However, the actual NumPy function is np.logspace. Using the wrong name in the documentation part of the code can lead to confusion. Let's update it to logspace.

Suggested change
# ndarray.logscale(start, stop, num, endpoint, base, dtype)
# ndarray.logspace(start, stop, num, endpoint, base, dtype)

# default base is 10
myArray = np.logspace(1.0, 3.0, num = 10)
print(myArray)

# [   10.            16.68100537    27.82559402    46.41588834    77.42636827
#    129.1549665    215.443469     359.38136638   599.48425032  1000.        ]

myArray = np.logspace(1.0, 3.0, num = 10, base = 2)
print(myArray)

# [ 2.          2.33305808  2.72158     3.1748021   3.70349885  4.32023896
#   5.0396842   5.87893797  6.85795186  8.        ]
83 changes: 83 additions & 0 deletions Test/P05_NumpyArrayManipulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Author: OMKAR PATHAK

# This example shows various array manipulation operations
import numpy as np

# numpy.reshape(array_to_reshape, tuple_of_new_shape) gives new shape (dimension) to our array
myArray = np.arange(0, 30, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Non-Standard Variable Naming (camelCase in Python)

In Python, variable names should follow the snake_case convention. Additionally, 'myArray' is a generic name; consider using a more descriptive name that reflects the content or purpose of the array.

Suggested change
myArray = np.arange(0, 30, 2)
even_numbers_array = np.arange(0, 30, 2)
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require snake_case for variable names
  2. 'myArray' is a generic name that lacks descriptive context about the data
  3. Consistent naming improves maintainability and aligns with the Python ecosystem

Gaps

  1. The variable name is functional and common in educational snippets
  2. camelCase is sometimes used in specific teams despite PEP 8 guidelines

print(myArray) # [ 0  2  4  6  8 10 12 14 16 18 20 22 24 26 28]

myArrayReshaped = myArray.reshape(5, 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Non-Standard Variable Naming (camelCase in Python)

Variable names in Python should use snake_case. 'myArrayReshaped' should be refactored to follow language standards and provide better semantic clarity.

Suggested change
myArrayReshaped = myArray.reshape(5, 3)
reshaped_numbers_matrix = even_numbers_array.reshape(5, 3)
Reasons & Gaps

Reasons

  1. Violates PEP 8 recommendation for lower_case_with_underscores in variables
  2. Mixing naming styles (camelCase vs snake_case) reduces codebase consistency
  3. Descriptive names like 'matrix' better reflect the 2D nature of the reshaped data

Gaps

  1. The name is technically descriptive of the operation performed
  2. Project-specific style guides might occasionally permit camelCase

print(myArrayReshaped)

# [[ 0  2  4]
#  [ 6  8 10]
#  [12 14 16]
#  [18 20 22]
#  [24 26 28]]

# numpy.ndarray.flat() returns an 1-D iterator
print(myArray.flat[5]) # 10

# numpy.ndarray.flatten() restores the reshaped array into a 1-D array
print(myArrayReshaped.flatten())

# numpy.tranpose() this helps to find the tranpose of the given array
print(myArrayReshaped.transpose())

# [[ 0  6 12 18 24]
#  [ 2  8 14 20 26]
#  [ 4 10 16 22 28]]

# numpy.swapaxes(array, axis1, axis2) interchanges the two axes of an array
originalArray = np.arange(8).reshape(2,2,2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Non-Standard Variable Naming (camelCase in Python)

Python variables should follow snake_case. Consider renaming 'originalArray' to 'original_array' or a more context-specific name to adhere to PEP 8 standards.

Suggested change
originalArray = np.arange(8).reshape(2,2,2)
original_3d_array = np.arange(8).reshape(2, 2, 2)
Reasons & Gaps

Reasons

  1. PEP 8 explicitly recommends snake_case for all variable and function names
  2. Standardizing on one casing style reduces cognitive load for Python developers
  3. Adding '3d' to the name provides immediate context about the array dimensions

Gaps

  1. The name 'originalArray' is clear in intent despite the casing violation
  2. Small scripts often use simpler naming that may deviate from strict standards

print(originalArray)

# [[[0 1]
#   [2 3]]
#  
#  [[4 5]
#   [6 7]]]

print(np.swapaxes(originalArray, 2, 0))

# [[[0 4]
#   [2 6]]
#  
#  [[1 5]
#   [3 7]]]

# numpy.rollaxis(arr, axis, start) rolls the specified axis backwards, until it lies in a specified position
print(np.rollaxis(originalArray, 2))

# [[[0 2]
#   [4 6]]
#  
#  [[1 3]
#   [5 7]]]

# numpy.resize(arr, shape) returns a new array with the specified size. If the new size is greater than
# the original, the repeated copies of entries in the original are contained

myArray = np.array([[1,2,3],[4,5,6]])
print(myArray)

# [[1 2 3]
#  [4 5 6]]

print(np.resize(myArray, (3, 2)))

# [[1 2]
#  [3 4]
#  [5 6]]

# numpy.append(array, values, axis)
myArray = np.array([[1,2,3],[4,5,6]])
print(myArray)

# [[1 2 3]
#  [4 5 6]]

print(np.append(myArray, [7, 8, 9]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 100%

JAS - Just a suggestion
Potential In-Place Modification Confusion

I noticed we're using np.append() here. It's important to remember that np.append() does not modify the original array in place but returns a new one. Since the result isn't assigned back to myArray, the original array remains unchanged for any subsequent operations. If the intent was to update the array, we should assign the result back to the variable.

Suggested change
print(np.append(myArray, [7, 8, 9]))
myArray = np.append(myArray, [7, 8, 9])


# [1 2 3 4 5 6 7 8 9]
43 changes: 43 additions & 0 deletions Test/P06_NumpyStringFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Author: OMKAR PATHAK

import numpy as np

abc = ['abc']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Non-Descriptive Variable Name

The variable name 'abc' is a placeholder that does not describe the data it contains. Using a more descriptive name like 'string_array' or 'input_labels' improves code maintainability.

Suggested change
abc = ['abc']
string_array = ['abc']
Reasons & Gaps

Reasons

  1. Variable names should reflect the purpose and content of the data stored
  2. 'abc' is a generic placeholder that fails to provide semantic meaning
  3. Descriptive naming reduces cognitive load when reading the logic flow

Gaps

  1. In short scripts or snippets, generic names are sometimes used for brevity
  2. The context of a string manipulation demo might tolerate simple names

xyz = ['xyz']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Non-Descriptive Variable Name

The variable name 'xyz' is a placeholder. Replacing it with a name that describes its role, such as 'suffix_array', makes the string concatenation logic easier to follow.

Suggested change
xyz = ['xyz']
suffix_array = ['xyz']
Reasons & Gaps

Reasons

  1. Meaningless names like 'xyz' require the reader to trace values manually
  2. Clearer names document the code's intent without needing extra comments
  3. Standardized naming improves consistency across the project's codebase

Gaps

  1. Small scripts often use x, y, z as generic identifiers for simple data
  2. The specific domain of this script is a basic library demonstration


# string concatenation
print(np.char.add(abc, xyz)) # ['abcxyz']

print(np.char.add(abc, 'pqr')) # ['abcpqr']

# string multiplication
print(np.char.multiply(abc, 3)) # ['abcabcabc']

# numpy.char.center: This function returns an array of the required width so that the input string is
# centered and padded on the left and right with fillchar.

print(np.char.center(abc, 20, fillchar = '*')) # ['********abc*********']

# numpy.char.capitalize(): This function returns the copy of the string with the first letter capitalized.
print(np.char.capitalize('hello world')) # Hello world

# numpy.char.title(): This function returns a title cased version of the input string with the first letter
# of each word capitalized.
print(np.char.title('hello how are you?')) # Hello How Are You?

# numpy.char.lower(): This function returns an array with elements converted to lowercase. It calls
# str.lower for each element.
print(np.char.lower(['HELLO','WORLD'])) # ['hello' 'world']

# numpy.char.upper(): This function calls str.upper function on each element in an array to return
# the uppercase array elements.
print(np.char.upper('hello')) # HELLO

# numpy.char.split(): This function returns a list of words in the input string. By default, a whitespace
# is used as a separator
print(np.char.split('Omkar Pathak')) # ['Omkar', 'Pathak']
print(np.char.split('2017-02-11', sep='-')) # ['2017', '02', '11']

# numpy.char.join(): This method returns a string in which the individual characters are joined by
# separator character specified.
print(np.char.join(':','dmy')) # d:m:y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 85%

JAS - Just a suggestion
Potential TypeError in String Joining

I noticed that we're using np.char.join with a single string 'dmy'. While this works for individual characters, if the intent was to join a list of strings (like 'day', 'month', 'year'), passing a single string will join its characters instead. If 'dmy' was meant to be a sequence of strings, it should be passed as a list to avoid unexpected character-level joining.

Suggested change
print(np.char.join(':','dmy')) # d:m:y
print(np.char.join(':', ['d', 'm', 'y']))
Reasons & Gaps

Reasons

  1. np.char.join treats a single string as a sequence of characters
  2. Joining 'dmy' results in 'd:m:y', which might not be the intended data structure
  3. Using a list makes the sequence of elements to be joined explicit and clear

Gaps

  1. The developer's intent for 'dmy' is not explicitly clear from the context
  2. The current code is syntactically valid but potentially logically misleading

30 changes: 30 additions & 0 deletions Test/P07_NumpyMathematicalFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Author: OMKAR PATHAK

import numpy as np

angles = np.array([0, 30, 45, 60, 90, 180, 360])

# Convert to radians by multiplying with pi/180
# for getting sine of angles
print(np.sin(angles * np.pi/180))

# for getting cosine of angles
print(np.cos(angles * np.pi/180))

# for getting tangent of angles
print(np.tan(angles * np.pi/180))

# for computing inverse of trigonometric functions
sine = np.sin(angles * np.pi/180)
sineinv = np.arcsin(sine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning Confidence Score: 100%

Potential Domain Error in Inverse Sine

I noticed we're calculating arcsin on the entire sine array. While this works for most values, np.sin can occasionally produce values slightly outside the [-1, 1] range due to floating-point precision errors (e.g., 1.0000000000000002). This would cause np.arcsin to return NaN for those elements. It's safer to clip the input values to the valid domain before computing the inverse.

Suggested change
sineinv = np.arcsin(sine)
sineinv = np.arcsin(np.clip(sine, -1, 1))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Cryptic Abbreviation in Variable Name

The variable name sineinv uses a cryptic abbreviation by concatenating 'sine' and 'inv'. Following Python naming conventions, it is better to use underscores for readability or a more descriptive name like sine_inverse or angles_in_radians.

Suggested change
sineinv = np.arcsin(sine)
sine_inverse = np.arcsin(sine)
Reasons & Gaps

Reasons

  1. Concatenated abbreviations like 'sineinv' increase cognitive load compared to snake_case
  2. Standard Python naming conventions (PEP 8) recommend using underscores to separate words
  3. Using 'sine_inverse' explicitly communicates the mathematical relationship of the data

Gaps

  1. 'inv' is a common mathematical abbreviation for inverse, which might be acceptable in scientific computing contexts
  2. The variable name is technically understandable within the local trigonometric context of the script

# computing angle from inverse
print(np.degrees(sineinv))

# for rounding the values
print(np.around(sine, 4)) # [ 0.      0.5     0.7071  0.866   1.      0.     -0.    ]

# for rounding to previous integer
print(np.floor(sine)) # [ 0.  0.  0.  0.  1.  0. -1.]

# for rounding to next integer
print(np.ceil(sine)) # [ 0.  1.  1.  1.  1.  1. -0.]
25 changes: 25 additions & 0 deletions Test/P08_NumpyArithmeticOperations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Author: OMKAR PATHAK

import numpy as np

firstArray = np.arange(12).reshape(3, 4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Variable Naming Convention Violation

The variable name 'firstArray' uses camelCase, which violates the Python snake_case naming convention. Additionally, 'firstArray' is partially generic; a name reflecting the data or shape would be more descriptive.

Suggested change
firstArray = np.arange(12).reshape(3, 4)
first_array = np.arange(12).reshape(3, 4)
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require snake_case for variable names
  2. Using camelCase in Python scripts reduces consistency with the standard library
  3. Descriptive names improve code maintainability and reduce cognitive load

Gaps

  1. The term 'array' is a technical term often accepted in mathematical or tutorial contexts
  2. Project-specific style guides might occasionally permit camelCase for consistency with other languages

print(firstArray)

secondArray = np.arange(4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning Confidence Score: 100%

Potential Division by Zero

I noticed that secondArray is initialized using np.arange(4), which creates the array [0, 1, 2, 3]. When we perform np.divide(firstArray, secondArray), the first element of secondArray is zero, which will result in a 'division by zero' warning and produce inf or nan values in the output. It's usually safer to ensure the divisor doesn't contain zeros or handle the resulting infinity values explicitly.

Suggested change
secondArray = np.arange(4)
secondArray = np.arange(1, 5)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Variable Naming Convention Violation

The variable name 'secondArray' uses camelCase instead of the standard Python snake_case. It is recommended to use descriptive names that follow the language's style guidelines.

Suggested change
secondArray = np.arange(4)
second_array = np.arange(4)
Reasons & Gaps

Reasons

  1. Violates PEP 8 recommendation for lowercase with underscores for variable names
  2. Mixed naming styles (camelCase in Python) can confuse developers from other backgrounds
  3. Consistent naming improves searchability and readability across the codebase

Gaps

  1. In simple arithmetic examples, ordinal naming (first, second) is common but not ideal
  2. Small script context might make strict naming enforcement feel pedantic

print(secondArray)

# adding above two arrays (NOTE: array shapes should be same)
print(np.add(firstArray, secondArray))

# subtracting above two arrays
print(np.subtract(firstArray, secondArray))

# multiplying above two arrays
print(np.multiply(firstArray, secondArray))

# dividing the above two arrays
print(np.divide(firstArray, secondArray))

# numpy.power(): returns array element raised to the specified value result
array = np.array([1, 2, 3])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Forbidden Generic Variable Name

The variable name 'array' is a forbidden generic name under the enterprise coding standard. It is too vague and matches a type name, which can lead to shadowing or confusion.

Suggested change
array = np.array([1, 2, 3])
input_array = np.array([1, 2, 3])
Reasons & Gaps

Reasons

  1. Generic names like 'array' fail to communicate the specific purpose of the data
  2. Using type-like names for variables can lead to naming collisions in larger scopes
  3. Specific names like 'input_array' or 'base_values' provide better semantic context

Gaps

  1. 'array' is a very common name in NumPy tutorials and short code snippets
  2. The context of a power operation makes the generic name somewhat understandable

print(np.power(array, 2)) # [1 4 9]
Loading
Loading