
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 26504 Articles for Server Side Programming

859 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

553 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

2K+ Views
We can override the backend value using atplotlib.rcParams['backend'] variable.StepsUsing get_backend() method, return the name of the current backend, i.e., default name.Now override the backend name.Using get_backend() method, return the name of the current backend, i.e., updated name.Exampleimport matplotlib print("Before, Backend used by matplotlib is: ", matplotlib.get_backend()) matplotlib.rcParams['backend'] = 'TkAgg' print("After, Backend used by matplotlib is: ", matplotlib.get_backend())OutputBefore, Backend used by matplotlib is: GTK3Agg After, Backend used by matplotlib is: TkAgg Enter number of bars: 5

4K+ Views
To make a custom color, we can create a hexadecimal string. From it, we can make different sets of color representation and can pass them into the scatter method to get the desired output.Using the set_color method, we could set the color of the bar.StepsTake user input for the number of bars.Add bar using plt.bar() method.Create colors from hexadecimal alphabets by choosing random characters.Set the color for every bar, using set_color() method.To show the figure we can use plt.show() method.Examplefrom matplotlib import pyplot as plt import random bar_count = int(input("Enter number of bars: ")) bars = plt.bar([i for ... Read More

3K+ Views
We will first create a numpy matrix and then find out the number of rows and columns in that matrixAlgorithmStep 1: Create a numpy matrix of random numbers. Step 2: Find the rows and columns of the matrix using numpy.shape function. Step 3: Print the number of rows and columns.Example Codeimport numpy as np matrix = np.random.rand(2,3) print(matrix) print("Total number of rows and columns in the given matrix are: ", matrix.shape)Output[[0.23226052 0.89690884 0.19813164] [0.85170808 0.97725669 0.72454096]] Total number of rows and columns in the given matrix are: (2, 3)

4K+ Views
In this program, we will print an identity matrix of size nxn where n will be taken as an input from the user. We shall use the identity() function in the numpy library which takes in the dimension and the data type of the elements as parametersAlgorithmStep 1: Import numpy. Step 2: Take dimensions as input from the user. Step 3: Print the identity matrix using numpy.identity() function.Example Codeimport numpy as np dimension = int(input("Enter the dimension of identitiy matrix: ")) identity_matrix = np.identity(dimension, dtype="int") print(identity_matrix)OutputEnter the dimension of identitiy matrix: 5 [[1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] [0 0 0 1 0] [0 0 0 0 1]]

1K+ Views
We have to create a numpy array in the range provided by the user. We will use the arange() function in the numpy library to get our output.AlgorithmStep1: Import numpy. Step 2: Take start_value, end_value and Step from the user. Step 3: Print the array using arange() function in numpy.Example Codeimport numpy as np start_val = int(input("Enter starting value: ")) end_val = int(input("Enter ending value: ")) Step_val = int(input("Enter Step value: ")) print(np.arange(start_val, end_val, Step_val))OutputEnter starting value: 5 Enter ending value: 50 Enter Step value: 5 [ 5 10 15 20 25 30 35 40 45]