
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

3K+ Views
In this problem, we have to add a vector/array to a numpy array. We will define the numpy array as well as the vector and add them to get the result arrayAlgorithmStep 1: Define a numpy array. Step 2: Define a vector. Step 3: Create a result array same as the original array. Step 4: Add vector to each row of the original array. Step 5: Print the result array.Example Codeimport numpy as np original_array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) print("Original Array: ", original_array) vector = np.array([1, 1, 0]) print("Vector: ... Read More

5K+ Views
Using plt.figure() method, we can create a figure and thereafter, we can create an axis. Using set_xticks and set_yticks, we can change the ticks format and ax.grid could help to specify the grid interval.StepsCreate a new figure, or activate an existing figure, using fig = plt.figure() method.Add an `~.axes.Axes` to the figure as part of a subplot arrangement, where nrow = 1, ncols = 1 and index = 1.Get or set the current tick locations and labels of the X-axis.Get or set the current tick locations and labels of the X-axis. With minor = True, Grid.Get or set the current ... Read More

4K+ Views
In this problem, we will find the sum of all the rows and all the columns separately. We will use the sum() function for obtaining the sum.AlgorithmStep 1: Import numpy. Step 2: Create a numpy matrix of mxn dimension. Step 3: Obtain the sum of all the rows. Step 4: Obtain the sum of all the columns.Example Codeimport numpy as np a = np.matrix('10 20; 30 40') print("Our matrix: ", a) sum_of_rows = np.sum(a, axis = 0) print("Sum of all the rows: ", sum_of_rows) sum_of_cols = np.sum(a, axis = 1) print("Sum of all the columns: ", sum_of_cols)OutputOur ... Read More

9K+ Views
To get a linear regression plot, we can use sklearn’s Linear Regression class, and further, we can draw the scatter points.StepsGet x data using np.random.random((20, 1)). Return random floats in the half-open interval[20, 1).Get the y data using np.random.normal() method. Draw random samples from a normal (Gaussian) distribution.Get ordinary least squares Linear Regression, i.e., model.Fit the linear model.Return evenly spaced numbers over a specified interval, using linspace() method.Predict using the linear model, using predict() method.Create a new figure, or activate an existing figure, with a given figsize tuple (4, 3).Add an axis to the current figure and make it the ... Read More

5K+ Views
First, we will create a polygon using the mplPath.Path method and to check whether a given point is in the polygon or not, we will use the method, poly_path.contains_point.StepsCreate a list of points to make the polygon.Create a new path with the given vertices and codes, using mplPath.Path().Check if point (200, 100) exists in the polygon or not, using contains_point() method. Return whether the (closed) path contains the given point. => TrueCheck if point (1200, 1000) exists in the polygon or not, using contains_point() method. Return whether the (closed) path contains the given point. => FalseExampleimport matplotlib.path as mplPath import ... Read More

864 Views
If we have a data frame that contains a character column and a named vector which has the same names as in the character column of the data frame then we can combine this data frame and the vector by using match function be appropriately defining the names and the character column. Check out the below example to understand how it can be done.ExampleConsider the below data frame df1 and the vector v1 − Live Demodf1

4K+ Views
To convert number to words in an R data frame column, we can use english function from english package. For example, if we have a data frame called df that contains a number column x then we can convert the numbers into words by using the command as.character(english(df$x)).ExampleConsider the below data frame − Live Demox

1K+ Views
To find the row product of a matrix in R, we can use apply function along with prod function. For example, if we have a matrix called M then to find the row product of a matrix we can use the command apply(M,1,prod). We need to remember that the output will be a vector not matrix. Check out the below examples to understand how to perform the row product of the matrix.ExampleConsider the below matrix − Live DemoM1

3K+ Views
In this program, we will add all the terms of a numpy matrix using the sum() function in the numpy library. We will first create a random numpy matrix and then, we will obtain the sum of all the elements.AlgorithmStep 1: Import numpy. Step 2: Create a random m×n matrix using the random() function. Step 3: Obtain the sum of all the elements in the matrix using the sum() function.Example Codeimport numpy as np matrix = np.random.rand(3, 3) print("The numpy matrix is: ", matrix) print("The sum of the matrix is: ", np.sum(matrix))OutputThe numpy matrix is: [[0.66411969 0.43672579 0.48448593] [0.76110384 ... Read More

556 Views
Using the subplot method, we can configure the number of rows and columns. nrows*nclos will create number positions to draw a diagram.StepsNumber of rows = 2, Number of columns = 1, so total locations are: 2*1 = 2.Add a subplot to the current figure, nrow = 2, ncols = 1, index = 1.Add a subplot to the current figure, nrow = 2, ncols = 1, index = 2.Using plt.show(), we can show the figure.Examplefrom matplotlib import pyplot as plt row_count = 2 col_count = 1 index1 = 1 # no. of subplots are: row*col, index is the position ... Read More