Example #1
0
class ChangeDT:

    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    # call this class functions from utility
    def calling(self):
        print("\ncreate matrix to store it into file: ")
        input1 = input("\nEnter the start value for array:")
        input2 = input("Enter the end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            # print("\nNew Matrix:\n", array_created)
            print("\nGive proper dimension:")
            num1 = input("Enter the 1st dimension:")
            num2 = input("Enter the 2nd dimension:")
            result = self.obj1.reshape_matrix(array_created, num1, num2)
            str2 = str(result)

            if re.match(str2, 'None'):
                print("Output will not display")
            else:
                print("Original Array: \n", result)
                # it will take as as header comment to input matrix
                res = self.obj1.change_dt(result)
                print("Array with other DataType: \n", res)
Example #2
0
class ArrayOperation:
    # arr1 = np.array([10,20,30,40][20,40,50,60])
    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    # call this class functions from utility
    def calling(self):
        print("\nCreate an array: ")
        input1 = input("\nEnter the start value for array:")
        input2 = input("Enter the end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            # print("\nNew Matrix:\n", array_created)
            print("\nGive proper dimension:")
            num1 = input("Enter the 1st dimension:")
            num2 = input("Enter the 2nd dimension:")
            result = self.obj1.reshape_matrix(array_created, num1, num2)
            str2 = str(result)

            if re.match(str2, 'None'):
                print("Output will not display")
            else:
                print("Reshape array into given format: \n", result)

                # it will take as as header comment to input matrix
                res = self.obj1.flattendarr(result)
                print("Flatted array: ", res)
class StoreArray:
    # arr1 = np.array([10,20,30,40][20,40,50,60])
    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    # call this class function from utility
    def calling(self):
        print("\nCreate array to store it into file: ")
        input1 = input("\nEnter the start value for array:")
        input2 = input("Enter the end value:")
        array_created = self.obj1.matrix_creation(input1, input2)

        str1 = str(array_created)
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            # print("\nNew Matrix:\n", array_created)
            print("\nGive proper dimension for matrix:")
            num1 = input("Enter the 1st dimension:")
            num2 = input("Enter the 2nd dimension:")
            result = self.obj1.reshape_matrix(array_created, num1, num2)

            str2 = str(result)

            if re.match(str2, 'None'):
                print("Output will not display")
            else:
                print("Reshape array into given format: \n", result)
                # it will take as as header comment to input matrix
                header = 'c1 c2 c3 '
                # file only create once and then it  will update with new inputs
                # savetxt function is used to store data into file
                np.savetxt('file12.txt', result, fmt=" %d ", header=header)
Example #4
0
class ThreeDArray:

    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    # call this class functions from utility
    def calling(self):
        print("\nCreate array ")
        input1 = input("\nEnter the array start value:")
        input2 = input("Enter the end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            # print("\nNew Matrix:\n", array_created)
            print("\nGive proper dimension for matrix:")
            num1 = input("Enter the 1st dimension:")
            num2 = input("Enter the 2nd dimension:")
            result = self.obj1.reshape_matrix(array_created, num1, num2)
            str2 = str(result)

            if re.match(str2, 'None'):
                print("Output will not display")
            else:
                print("Original Array: \n", result)
                # it will take as as header comment to input matrix
                res = self.obj1.identitymatrix(result)
                print("3-D array with ones on a diagonal: \n", res)
Example #5
0
class NumpyClass1:
    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    # call this class function from utility
    def calling(self):
        print("\nPut values for reshape matrix from 2 to 10")
        input1 = input("\nEnter the matrix start value:")
        input2 = input("Enter the matrix end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            print("\nNew Matrix:\n", array_created)
            print("\n3 * 3 Dimension matrix")
            num1 = input("Enter the 1st dimension:")
            num2 = input("Enter the 2nd dimension:")
            result = self.obj1.reshape_matrix(array_created, num1, num2)
            str2 = str(result)

            if re.match(str2, 'None'):
                print("Output will not display")
            else:
                print("Reshape given matrix into given dimension: \n", result)
 def __init__(self):
     # list created
     self.list1 = [1, 2, 3, 4, 5, 6, 7, 8]
     # tuple created
     self.tuple1 = ((8, 4, 6), (1, 2, 3))
     # utility class objected created here
     self.obj1 = UtilClass()
Example #7
0
class NumpyClass1:
    # class constructor
    def __init__(self):
        self.obj1 = UtilClass()

    def calling(self):
        print("\nPut values from 12 to 37 to reverse array ")
        # It display number from 12 to 37
        input1 = input("\nEnter the matrix start value:")
        input2 = input("Enter the matrix end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            print("\nOriginal Matrix:", array_created)
            # call reverse method
            print("Reverse array:", self.obj1.matrix_reverse(array_created))
class Checkerboard:
    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    def calling(self):
        print("\nPut values from 1 to 64  ")
        # It display number from 1 to 64
        input1 = input("\nEnter the matrix start value:")
        input2 = input("Enter the matrix end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        # check output correct or not
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            # print("\nNew Matrix:\n", array_created)
            print("\n 8 * 8 Dimension matrix")
            # whole matrix fill with zeroes
            matrix_of_one = self.obj1.null_vector_creation(array_created)
            num1 = input("Enter the 1st dimension:")
            num2 = input("Enter the 2nd dimension:")
            result = self.obj1.reshape_matrix(matrix_of_one, num1, num2)
            str2 = str(result)

            if re.match(str2, 'None'):
                print("Output will not display")
            else:
                print("Reshape given matrix into 8*8 or given format: \n", result)
                """ x[1::2, ::2] = 1 : Slice from 1st index row till 1+2+2… (repeated for 2nd iteration)and 
                                        fill all columns with 1 starting from 0th to 0+2+2… and so on.
                    
                    x[::2, 1::2] = 1 : Slice from 0th row till 0+2+2… and 
                                        fill all columns with 1 starting from 1 to 1+2+2+….. """
                result[::2, 1::2] = 1
                result[1::2, ::2] = 1
                print("Checkerboard pattern:\n", result)
Example #9
0
class Matrix:
    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    def calling(self):
        print("\nPut values from 1 to 9  ")
        # It display number from 1 to 9
        input1 = input("\nEnter the matrix start value:")
        input2 = input("Enter the matrix end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        # check output correct or not
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            # print("\nNew Matrix:\n", array_created)
            print("\n 3 * 3 Dimension matrix")
            matrix_of_one = self.obj1.matrix_one_creation(array_created)
            num1 = input("Enter the 1st dimension:")
            num2 = input("Enter the 2nd dimension:")
            result = self.obj1.reshape_matrix(matrix_of_one, num1, num2)
            str2 = str(result)

            if re.match(str2, 'None'):
                print("Output will not display")
            else:
                print("Reshape given matrix into 3*3 or given format: \n",
                      result)
                print("\n0 on the border and 1 inside in the array")
                # Give result as zero outside and border with zeroes
                # syntax->numpy.pad(array, pad_width, mode, **kwargs)
                result1 = np.pad(result,
                                 pad_width=1,
                                 mode='constant',
                                 constant_values=0)
                print(result1)
Example #10
0
class NumpyClass1:
    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    def calling(self):

        print("\nPut values for null vector from 0 to 10")
        input1 = input("\nEnter the matrix start value:")
        input2 = input("Enter the matrix end value:")
        array_created = self.obj1.matrix_creation(input1, input2)
        str1 = str(array_created)
        if re.match(str1, 'None'):
            print("Output will not display")
        else:
            # print("\nNew Matrix:\n", array_created)
            # create null vector
            result = self.obj1.null_vector_creation(array_created)

            print("\nOriginal null vector array :", result)
            # update null vector sixth value to 11
            print("Update array: ", self.obj1.update_matrix(result))
Example #11
0
 def __init__(self):
     self.obj1 = UtilClass()
Example #12
0
class PandaDataFrame:
    def __init__(self):
        # create obj for utility class
        self.obj1 = UtilClass()

    def calling(self):
        while True:
            try:
                print()
                print(
                    "1. Create and display a DataFrame from a specified dictionary ."
                    "\n"
                    "2. Display a summary of the basic information "
                    "\n"
                    "3. Get the first 3 rows of a given DataFrame"
                    "\n"
                    "4. Select the 'name' and 'score' columns"
                    "\n"
                    "5. Select 'name' and 'score' columns in rows 1, 3, 5, 6 from data frame"
                    "\n"
                    "6. Select the rows where the number of attempts in the examination is greater than 2"
                    "\n"
                    "7. Count the number of rows and columns "
                    "\n"
                    "8. Select the rows where the score is missing, i.e. is NaN"
                    "\n"
                    "9. select the rows where attempts is less than 2 and score greater than 15"
                    "\n"
                    "10. Change the score in row 'd' to 11.5"
                    "\n"
                    "11. Calculate the sum of the examination attempts"
                    "\n"
                    "12. Calculate the mean score for each different student"
                    "\n"
                    "13. Append a new row 'k' to data frame"
                    "\n"
                    "14. Sort the DataFrame"
                    "\n"
                    "15. Replace the 'qualify' column contains the values 'yes' and 'no' with True and False"
                    "\n"
                    "16. Delete the 'attempts' column"
                    "\n"
                    "17. Insert a new column in existing DataFrame"
                    "\n"
                    "18. Iterate over rows in a DataFrame"
                    "\n"
                    "19. Get list from DataFrame column headers"
                    "\n"
                    "20. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():
                    if choice == 1:
                        # pandas DF created and display
                        print("Pandas Data Frame:\n",
                              self.obj1.create_panda_data_frame())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        # It will show the summary
                        print("Panda Data Frame Summary: ")
                        print(self.obj1.display_summary())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        rows_input = int(input("Enter the number to see rows"))
                        print(self.obj1.display_rows(rows_input))
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        # select name and score from DF
                        print("Specific col\n ", self.obj1.show_specific_col())

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 5:
                        # specify column and rows from given DF
                        # name' and 'score' columns in rows 1, 3, 5, 6 from data frame
                        print("\n", self.obj1.display_row_from_col())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 6:
                        # select rows where no. of attempts greater than 2
                        # select specify row and column
                        print(self.obj1.show_greator_attemps())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 7:
                        # count number of rows and columns
                        self.obj1.count_rows_col()
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 8:
                        # select rows where score is missing, i. e. NAN
                        print("\nRows where score is missing\n",
                              self.obj1.null_score())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 9:
                        # Num of attempts in examination is 2 & score > 15
                        print(
                            "\nNum of attempts in examination is 2 & score > 15\n",
                            self.obj1.num_attempts())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 10:
                        # Change the score in row 'd'
                        value = float(input("Enter new score for 'd' "))
                        print("Change the score in row 'd'\n",
                              self.obj1.change_score(value))
                        print(
                            "_______________________________________________________________________________"
                        )
                    elif choice == 11:
                        # show sum of all attempts
                        print("Sum of attempts for each:\n",
                              self.obj1.sum_attemps())
                        print(
                            "_______________________________________________________________________________"
                        )
                    elif choice == 12:
                        # calculate mean score
                        print("\nMean value for score: \n",
                              self.obj1.calculate_mean())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 13:
                        # append new row k to data frame
                        self.obj1.add_del_new_row()
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 14:
                        # sort data frame
                        print("Data frame after sorting\n")
                        print("Data after asc order sorting by score:\n",
                              self.obj1.sorting())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 15:
                        # In quality column replace 'yes' and 'no' by 'true' and 'false'
                        print(
                            "\nData frame after replacing qualify values: \n",
                            self.obj1.replace_values())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 16:
                        # delete attempt col from DF
                        print("DF after removing col attempts:\n",
                              self.obj1.delete_dataframe_col())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 17:
                        # insert new column in existing DF
                        print("\nDF after inserting new col:\n ",
                              self.obj1.inser_new_col())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 18:
                        # iterate over rows
                        self.obj1.iterate_rows()
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 19:
                        # get list from DF col headers
                        print("Data frame column \n", self.obj1.get_cols())
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 20:
                        exit()
                        print(
                            "_______________________________________________________________________________"
                        )

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        continue

                else:
                    raise ValueError
            except ValueError as e:
                print("\nInvalid Input", e)
Example #13
0
class PandaSeries:
    def __init__(self):
        self.obj1 = UtilClass()

    def calling(self):
        while True:
            try:
                print()
                print(
                    "1. Create and display a one-dimensional array using Pandas module."
                    "\n"
                    "2. Convert a Panda module Series to Python list "
                    "\n"
                    "3. Add, subtract, multiple and divide two Pandas Series"
                    "\n"
                    "4. Get the powers of an array values element-wise"
                    "\n"
                    "5. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():
                    if choice == 1:
                        size = input("Enter the size for list:")
                        panada1d_series = self.obj1.create_series(size)
                        print("One-dimensional array using Pandas Series:\n",
                              panada1d_series)

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        size = input("Enter the size for list:")
                        panada1d_series1 = self.obj1.create_series(size)
                        string = str(panada1d_series1)
                        if re.match(string, 'None'):
                            # If set is empty create again and then show its iteration again
                            print("Empty series")
                            continue

                        else:
                            print("Pandas Series:\n", panada1d_series1)
                            print("Panda series to list: ",
                                  self.obj1.conversion(panada1d_series1))
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        series1 = pd.Series([2, 4, 6, 8, 10])
                        series2 = pd.Series([1, 3, 5, 7, 9])
                        self.obj1.series_operations(series1, series2)

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        panda_series = pd.Series([1, 2, 3, 4])
                        print("Original panda series :", panda_series)
                        print("Power of 2 for all elements: ",
                              self.obj1.series_power(panda_series))

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 5:
                        exit()
                        print(
                            "_______________________________________________________________________________"
                        )

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        continue

                else:
                    raise ValueError
            except ValueError as e:
                print("\nInvalid Input", e)
Example #14
0
 def __init__(self):
     # create obj for utility class
     self.obj1 = UtilClass()
Example #15
0
 def __init__(self):
     # list created
     self.list1 = [10, 20, 30]
     # utility class objected created here
     self.obj1 = UtilClass()
Example #16
0
class Matplotlib:
    # class constructor
    def __init__(self):
        self.obj1 = UtilClass()

    def calling(self):
        while True:
            try:
                print()
                print(
                    "1. Draw a line with suitable label on the x axis, y axis and a title"
                    "\n"
                    "2. Draw a line values taken from a text file and a title.  "
                    "\n"
                    "3. Draw line charts of the financial data by using csv file\n"
                    "4. Plot two or more lines on same plot with suitable legends of each line"
                    "\n"
                    "5. Plot two or more lines with legends, different widths and colors"
                    "\n"
                    "6. Plot two or more lines with different styles"
                    "\n"
                    "7. Plot two or more lines and set the line markers."
                    "\n"
                    "8. Display the current axis limits values and set new axis values"
                    "\n"
                    "9. Plot quantities which have an x and y position."
                    "\n"
                    "10. Plot several lines with different format styles in one command using arrays"
                    "\n"
                    "11. Create multiple types of charts "
                    "\n"
                    "12. Customized the grid lines with linestyle -, width .5. and color blue"
                    "\n"
                    "13. Customized the grid lines with rendering with a larger grid and a smaller grid"
                    "\n"
                    "14. Create multiple plots"
                    "\n"
                    "5. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():
                    if choice == 1:
                        """1.Program to draw a line with suitable label in the x axis, y axis and title,
                         2. Draw a line using given axis values with suitable label in the x axis , y axis and a title"""

                        size = input("Enter the size for X and Y axis:")
                        x_axis = self.obj1.creatlist(size)
                        print(x_axis)
                        y_axis = self.obj1.creatlist(size)
                        print(y_axis)

                        self.obj1.draw_line_matplotlib(x_axis, y_axis)

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        """3. Draw a line using given axis values taken from a text file, 
                        with suitable label in the x axis, y axis and a title."""
                        self.obj1.read_text_file()

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        """ Write a Python program to draw line charts of the financial data of Alphabet Inc. 
                        between October 3, 2016 to October 7, 2016. Sample Financial data (fdata.csv)"""
                        self.obj1.read_data()
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        """Plot two or more lines on same plot with suitable legends of each line."""
                        size = input("Enter the size for 1st line:")
                        x1_axis = self.obj1.creatlist(size)
                        print(x1_axis)
                        y1_axis = self.obj1.creatlist(size)
                        print(y1_axis)
                        size = input("Enter the size for 2nd line:")
                        x2_axis = self.obj1.creatlist(size)
                        print(x2_axis)
                        y2_axis = self.obj1.creatlist(size)
                        print(y2_axis)

                        self.obj1.draw__multiple_line(x1_axis, y1_axis,
                                                      x2_axis, y2_axis)
                        # self.obj1.draw_line_matplotlib(x1_axis, y1_axis)
                        # self.obj1.draw_line_matplotlib(x1_axis, y1_axis)

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 5:
                        """plot two or more lines with legends, different widths and colors"""
                        size = input("Enter the size for 1st line:")
                        x1_axis = self.obj1.creatlist(size)
                        print(x1_axis)
                        y1_axis = self.obj1.creatlist(size)
                        print(y1_axis)
                        size = input("Enter the size for 2nd line:")
                        x2_axis = self.obj1.creatlist(size)
                        print(x2_axis)
                        y2_axis = self.obj1.creatlist(size)
                        print(y2_axis)

                        self.obj1.draw__line_with_color(
                            x1_axis, y1_axis, x2_axis, y2_axis)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 6:
                        """plot two or more lines with different styles"""
                        size = input("Enter the size for 1st line:")
                        x1_axis = self.obj1.creatlist(size)
                        print(x1_axis)
                        y1_axis = self.obj1.creatlist(size)
                        print(y1_axis)
                        size = input("Enter the size for 2nd line:")
                        x2_axis = self.obj1.creatlist(size)
                        print(x2_axis)
                        y2_axis = self.obj1.creatlist(size)
                        print(y2_axis)

                        self.obj1.plot_line_with_style(x1_axis, y1_axis,
                                                       x2_axis, y2_axis)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 7:
                        """plot two or more lines and set the line markers."""
                        size = input("Enter the size for 1st line:")
                        x1_axis = self.obj1.creatlist(size)
                        print(x1_axis)
                        y1_axis = self.obj1.creatlist(size)
                        print(y1_axis)
                        size = input("Enter the size for 2nd line:")
                        x2_axis = self.obj1.creatlist(size)
                        print(x2_axis)
                        y2_axis = self.obj1.creatlist(size)
                        print(y2_axis)

                        self.obj1.line_marker(x1_axis, y1_axis, x2_axis,
                                              y2_axis)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 8:
                        """display the current axis limits values and set new axis values"""
                        self.obj1.type_chart()
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 9:
                        """plot quantities which have an x and y position."""

                        size = input("Enter the size for 1st line:")
                        x1_axis = self.obj1.creatlist(size)
                        print(x1_axis)
                        y1_axis = self.obj1.creatlist(size)
                        print(y1_axis)
                        size = input("Enter the size for 2nd line:")
                        x2_axis = self.obj1.creatlist(size)
                        print(x2_axis)
                        y2_axis = self.obj1.creatlist(size)
                        print(y2_axis)

                        self.obj1.plot_quantities(x1_axis, y1_axis, x2_axis,
                                                  y2_axis)

                        print(
                            "_______________________________________________________________________________"
                        )
                    elif choice == 10:
                        """ plot several lines with different format styles in one command using arrays"""
                        self.obj1.draw_line_with_diff_formats_witharray()
                        print(
                            "_______________________________________________________________________________"
                        )
                    elif choice == 11:
                        """create multiple types of charts"""
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 12:
                        """Write a Python program to display the grid and draw line charts of the closing value of 
                        Alphabet Inc. between October 3, 2016 to October 7, 2016. Customized the grid lines with
                         linestyle -, width .5. and color blue."""
                        self.obj1.custom_grid()
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 13:
                        """Write a Python program to display the grid and draw line charts of the closing value of 
                        Alphabet Inc. between October 3, 2016 to October 7, 2016. Customized the grid lines with 
                        rendering with a larger grid (major grid) and a smaller grid (minor grid).Turn on the grid 
                        but turn off ticks. """
                        self.obj1.large_small_grid()

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 14:
                        """program to create multiple plots"""

                        size = input("Enter the size for 1st line:")
                        x1_axis = self.obj1.creatlist(size)
                        print(x1_axis)
                        y1_axis = self.obj1.creatlist(size)
                        print(y1_axis)
                        size = input("Enter the size for 2nd line:")
                        x2_axis = self.obj1.creatlist(size)
                        print(x2_axis)
                        y2_axis = self.obj1.creatlist(size)
                        print(y2_axis)

                        self.obj1.create_subplot(x1_axis, y1_axis, x2_axis,
                                                 y2_axis)
                        print(
                            "_______________________________________________________________________________"
                        )

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        continue

                else:
                    raise ValueError
            except ValueError as e:
                print("\nInvalid Input", e)
class MatplotlibBarChart:

    # class constructor
    def __init__(self):
        self.obj1 = UtilClass()

    # creates utility class object
    utility_obj = UtilityClass()

    # accept size of points you wanna accept
    size = utility_obj.accept_size()

    # accepts x axis values
    # print("Enter programming languages")
    language = utility_obj.accept_languages(size)
    print(language)

    # accepts y axis values
    print("Enter popularity")
    popularity = utility_obj.accept_popularity(size)
    print(popularity)

    # Set the x axis label
    plt.xlabel("Languages")

    # Set the y axis label
    plt.ylabel("Popularity")

    # Sets a title
    plt.title("Popularity of Programming Languages")

    def menu(self):
        print()
        print("1.Print output vertically")
        print("2.Print output horizontally")
        print("3.Bar with Uniform color")
        print("4.Bar with different color")
        print("5.Attach a text label above each bar displaying its popularity")
        print("6.Make blue border to each bar")
        print("9.Increase bottom margin")
        print("0.Exit")
        flag = False

        while not flag:
            try:
                choice = int(input("\nEnter your choice"))
                if choice >= 0 and choice <= 15:

                    if choice == 1:
                        self.obj1.draw_bar_vertically(self.language,
                                                      self.popularity)

                    if choice == 2:
                        self.obj1.draw_bar_horizontally(
                            self.language, self.popularity)

                    if choice == 3:
                        self.obj1.draw_bar_with_uniform_color(
                            self.language, self.popularity)

                    if choice == 4:
                        self.obj1.draw_bar_with_diff_color(
                            self.language, self.popularity)

                    if choice == 5:
                        self.obj1.attach_label(self.language, self.popularity)

                    if choice == 6:
                        self.obj1.make_border(self.language, self.popularity)

                    if choice == 8:
                        self.obj1.specify_width_position(
                            self.language, self.popularity)

                    if choice == 9:
                        self.obj1.increase_margin(self.language,
                                                  self.popularity)

                    if choice == 0:
                        flag = True
                else:
                    raise ValueError
            except ValueError:
                print("\nPlease give valid input and Try again")
 def __init__(self):
     # create obj of util class
     self.obj1 = UtilClass()
Example #19
0
class ThreeDArray:

    # class constructor
    def __init__(self):
        # utility class objected created here
        self.obj1 = UtilClass()

    # call this class functions from utility # 19 to 21
    def calling(self):
        while True:
            try:
                print()
                print(
                    "1. Create an array as per requirement"
                    "\n"
                    "2. Concatenate 2-dimensional arrays"
                    "\n"
                    "3. Make an array immutable (read-only)"
                    "\n"
                    "4. Create an array of (3, 4) shape, multiply every element value by 3"
                    "\n"
                    "5. Convert a NumPy array into Python list structure "
                    "\n"
                    "6. Add an extra column to an numpy array"
                    "\n"
                    "7. Remove specific elements in a numpy array"
                    "\n"
                    "8. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():
                    if choice == 1:
                        """19. Write a Python program to create an array which looks like below array. """
                        array = np.tri(4, 3, -1)
                        print("Final array: \n", array)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        # 20
                        data1 = np.array([[0, 1, 3], [5, 7, 9]])
                        data2 = np.array([[0, 2, 4], [6, 8, 10]])
                        print("original arrays:\n", data1, "\n", data2)
                        print("Concreate array:",
                              self.obj1.concreate_data(data1, data2))
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        # 21
                        print("\nPut values from 0 to 10")
                        input1 = input("\nEnter the start value of array:")
                        input2 = input("Enter the end value:")
                        array_created = self.obj1.matrix_creation(
                            input1, input2)
                        str1 = str(array_created)
                        if re.match(str1, 'None'):
                            print("Output will not display")
                        else:
                            # print("\nNew Matrix:\n", array_created)
                            # create null vector
                            result = self.obj1.null_vector_creation(
                                array_created)

                            print("\nOriginal null vector array :", result)
                            # print("try to change value for null")
                            a = np.zeros((3, 3))
                            # here we set writable = false , so we can only read our data
                            result.flags.writeable = False
                            result[0] = 1
                            print(result)

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        # 22
                        print("\nPut values from 1 to 12  ")

                        input1 = input("\nEnter the matrix start value:")
                        input2 = input("Enter the matrix end value:")
                        array_created = self.obj1.matrix_creation(
                            input1, input2)
                        str1 = str(array_created)
                        # check output correct or not
                        if re.match(str1, 'None'):
                            print("Output will not display")
                        else:
                            # print("\nNew Matrix:\n", array_created)
                            print("\n 3 *4 Dimension matrix")

                            num1 = input("Enter the 1st dimension:")
                            num2 = input("Enter the 2nd dimension:")
                            result = self.obj1.reshape_matrix(
                                array_created, num1, num2)
                            str2 = str(result)

                            if re.match(str2, 'None'):
                                print("Output will not display")
                            else:
                                print(
                                    "Reshape given matrix into given dimension format: \n",
                                    result)
                                # multiply each element in array by 3
                                num = 3
                                print(
                                    "Array  multiply every element value by 3: \n",
                                    self.obj1.matrix_scalar_multi(result, num))

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 5:
                        # 23
                        original_array = np.array([[0, 1], [2, 3], [4, 5]])
                        print("\nOriginal array: \n", original_array)
                        print("Array to list conversion:",
                              original_array.tolist())
                        # 24
                        original_array1 = np.array([
                            0.26153123, 0.52760141, 0.5718299, 0.5927067,
                            0.7831874, 0.69746349, 0.35399976, 0.99469633,
                            0.0694458, 0.54711478
                        ])
                        print("\nOriginal array: \n", original_array1)

                        np.set_printoptions(precision=3)
                        print("\nArray to list conversion with precision 3:",
                              original_array1)

                        # 25
                        original_array2 = np.array([1.6e-10, 1.6, 1200, .235])
                        print("\nOriginal array: ", original_array2)
                        # np.set_printoptions(suppress=True)
                        np.set_printoptions(suppress=True)
                        print("Final array:", original_array2)

                    elif choice == 6:
                        # 26
                        inputarr = np.array([[10, 20, 30], [40, 50, 60]])
                        addarray = np.array([[100], [200]])
                        # np.append() add new coloumn to original array with axis = 1 for 2D array
                        print(np.append(inputarr, addarray, axis=1))

                    elif choice == 7:
                        # 27
                        array_input = np.array(
                            [10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
                        index = (0, 3, 4)
                        print(np.delete(array_input, index))
                    elif choice == 8:
                        exit()
                        print(
                            "_______________________________________________________________________________"
                        )

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        continue

                else:
                    raise ValueError
            except ValueError as e:
                print("\nInvalid Input", e)
Example #20
0
 def __init__(self):
     # utility class objected created here
     self.obj1 = UtilClass()
class SizeofElements:
    # class constructor
    def __init__(self):
        # create obj of util class
        self.obj1 = UtilClass()

    def calling(self):
        while True:
            try:
                print()
                print(
                    "1. Find the number of elements,length in byte and total Bytes of an array"
                    "\n"
                    "2. Operation on array :"
                    "\n"
                    "3. Compare two arrays using numpy"
                    "\n"
                    "4. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():
                    if choice == 1:
                        # find the number of elements of an array
                        self.obj1.array_size_ele()

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        """find common values between two arrays
                        find the set difference of two arrays
                        Set exclusive-or will return the sorted, unique values """
                        self.obj1.operation_on_two_arrays()

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        # compare two arrays using numpy
                        self.obj1.compare_two_array()

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        # Exit from code
                        exit()

                        print(
                            "_______________________________________________________________________________"
                        )

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    # if acc == 'y' and acc == 'yes':
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        continue

                else:
                    raise ValueError

            except ValueError as e:
                print("\nInvalid Input", e)