When it is required to find the sum of the length of string at specific indices, the ‘enumerate’ is used to iterate through the elements in the list and adding the length of the element to a list.ExampleBelow is a demonstration of the samemy_list = ["python", "is", "best", "for", "coders"] print("The list is :") print(my_list) index_list = [0, 1, 4] result = 0 for index, element in enumerate(my_list): if index in index_list: result += len(element) print("The result is :") print(result)OutputThe list is : ['python', 'is', 'best', 'for', ... Read More
When it is required to test if the elements are in the min/max range, the list elements are iterated over, and are checked to see if it is equal to ‘max’ value.ExampleBelow is a demonstration of the samemy_list = [5, 6, 4, 7, 8, 13, 15] print("The list is : ") print(my_list) range_list = [4, 7, 10, 6] my_result = True for elem in range_list: if elem!= max(my_list): my_result = False break if(elem == True): print("All the elements are ... Read More
When it is required to find the mean deviation of the elements of a list, the ‘sum’ method and the ‘len’ method is used.ExampleBelow is a demonstration of the samemy_list = [3, 5, 7, 10, 12] print("The list is :") print(my_list) my_mean = sum(my_list) / len(my_list) my_variance = sum([((x – my_mean) ** 2) for x in my_list]) / len(my_list) my_result = my_variance ** 0.5 print("The result is :") print(result)OutputThe original list : [3, 5, 7, 10, 12] the standard deviation of list is : 3.2619012860600183ExplanationA list is defined and is displayed on the console.The ‘sum’ of the ... Read More
To set labels in matplotlib.hlines, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Add a horizontal line across the axis, y=1, with y=1 label, color='orange'.Add a horizontal line across the axis, y=2, with y=2 label, color='red'.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Add horizontal line plt.hlines(y=1, xmin=1, xmax=4, lw=7, color='orange') plt.text(4, 1, 'y=1', ha='left', va='center') # Add another horizontal line plt.hlines(y=2, xmin=2, xmax=5, lw=7, color='red') plt.text(2, 2, 'y=2', ha='right', va='center') ... Read More
To make a scatter plot for clustering in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points, Cluster and centers using numpy.Create a new figure or activate an existing figure.Add a subplot arrangement to the current figure.Plot the scatter data points using scatter() method.Iterate centers data and place marker using scatter() method.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.randn(10) y = np.random.randn(10) Cluster = np.array([0, 1, ... Read More
To put a circle with annotation in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create data points using numpy.Get the point coordinate to put circle with annotation.Get the current axis.Plot the data and data points using plot() method.Set X and Y axes scale.To put a circled marker, use the plot() method with marker='o' and some properties.Annotate that circle (Step 7) with arrow style.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.array([[5, ... Read More
The Arithmetic Average Return is calculated by adding the rate of returns of "n" sub-periods and then dividing the result by "n". In other words, the returns of "n" sub-periods are added and then divided by "n" to find the value of the average return. As it is also the process of finding the average of a series of numbers, the average return is sometimes called as "Arithmetic Average Return".Here is the formula to calculate Arithmetic Average Return −$$\mathrm{Average\:Return =\frac{Total\:Value\:of\:the\:Return}{Total\:Number\:of \:Returns}}$$Investors and market analysts normally use the arithmetic average return to check the past performance of a stock. It is ... Read More
The typical reason for an investor to invest in a financial instrument is to make current income from dividends and interest income. For a stable company, the investments will earn a reasonable return that is the Expected Rate of Return (ERR) on given investments. Some investments such as debentures, bank deposits, public deposits, bonds, etc. carry a predetermined fixed rate of return that is usually payable periodically.Note − The sole aim of the investor investing in a single asset is to get the maximum returns. Some fixed income instruments offer less returns, but they are less risky too. Increasingly risky ... Read More
Present Value of Growth Opportunities or PVGO represents the component of a company’s share value that relates to expectations of the investors in the growth of earnings. PVGO is the difference between the total value of a company’s shares from which the net present value of its earnings is deducted, assuming there is no growth in the values of the share. PVGO is also known as "value of growth".A company’s future income can be better represented in two layers: the first layer represents a perpetuity having constant return and the second layer represents the future growth in earnings.$$\mathrm{𝑉_{0} = PV_{NG} ... Read More
Rather than taking each rate of return and multiplying them with the weight to get the total weight of each asset, there is a simple formula to calculate the expected rate of return. The expected rate of return of a portfolio or simply the return of a portfolio is the given weighted average of the expected returns on the assets.ExampleLet's take an example of a two-asset portfolio and see how to calculate its expected return. Let’s assume an investor has invested 50% of his investment in X and 50% in Y.$$\mathrm{ERR\:of\:Portfolio = (Weight\:of\:Security\:X × 0.5) + (Weight\:of \:Security\:Y × 0.5)}$$Note ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP