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
Programming Articles - Page 1308 of 3366
1K+ Views
First, we can create an array matrix with some np.nan value, and using imshow method, we can create a diagram for that matrix.StepsCreate a new figure, or activate an existing figure.Add an `~.axes.Axes` to the figure as part of a subplot arrangement, nrows = 1, ncols = 1, index = 1.Create a 2D array with np.nan.Display data as an image, i.e., on a 2D regular raster.Use the draw() method which draws the drawing at the given location.To show the figure, use the plt.show() method.Exampleimport numpy as np import matplotlib.pyplot as plt f = plt.figure() ax = f.add_subplot(111) a = ... Read More
908 Views
To convert the row values in a matrix to row percentage, we can find the row sums and divide each row value by this sum. For example, if we have a matrix called M then we can convert the row values in M to row percentage by using the commandround((M/rowSums(M))*100,2)ExampleConsider the below matrix − Live DemoM1
543 Views
To get the axes instance, we will use the subplots() method.StepsMake a list of years.Make a list of populations in that year.Get the number of labels using np.arrange(len(years)) method.Set the width of the bars.Create fig and ax variables using subplots() method, where default nrows and ncols are 1.Set the Y-axis label of the figure using set_ylabel().Set the title of the figure, using set_title() method.Set the x-ticks with x that is created in step 3, using set_xticks method.Set the xtick_labels with years data, using set_xticklabels method.Use plt.show() method to show the figure.Examplefrom matplotlib import pyplot as plt import numpy as np ... Read More
7K+ Views
Whenever Y value list will be made, then we will convert those datasets into a new list, with ceil and floor value of the given list accordingly. Then, we can plot the graph for the new list data.StepsTake an input list.Find the minimum and maximum values in the input list (Step 1).Create a range between min and max value (Step 2).Get or set the current tick locations and labels of the Y-axis, with a new list.Set the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.Set a title for the axes.To show the figure we can use the ... Read More
273 Views
pylab is a module that imports matplotlib.pyplot (for plotting) and numpy (for mathematics and working with arrays) in a single namespace.Although many examples use pylab, it is no longer recommended. For non-interactive plotting, it is suggested to use pyplot to create the figures and then the OO interface for plotting.Exampleimport matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 2, 100) plt.plot(x, x, label='linear') plt.plot(x, x**2, label='quadratic') plt.plot(x, x**3, label='cubic') plt.xlabel('x label') plt.ylabel('y label') plt.title("Simple Plot") plt.legend() plt.show()Output
850 Views
In this program, we have to print elements of a numpy array in a given range. The different numpy functions used are numpy.where() and numpy.logical_and().AlgorithmStep 1: Define a numpy array. Step 2: Use np.where() and np.logical_and() to find the numbers within the given range. Step 3: Print the result.Example Codeimport numpy as np arr = np.array([1,3,5,7,10,2,4,6,8,10,36]) print("Original Array:",arr) result = np.where(np.logical_and(arr>=4, arr
11K+ Views
In this program, we will find the set difference of two numpy arrays. We will use the setdiff1d() function in the numpy library. This function takes two parameters: array1 and array2 and returns the unique values in array1 that are not in array2.AlgorithmStep 1: Import numpy. Step 2: Define two numpy arrays. Step 3: Find the set difference between these arrays using the setdiff1d() function. Step 4: Print the output.Example Codeimport numpy as np array_1 = np.array([2, 4, 6, 8, 10, 12]) print("Array 1: ", array_1) array_2 = np.array([4, 8, 12]) print("Array 2: ", array_2) set_diff = ... Read More
3K+ Views
In this problem, we will find the intersection between two numpy arrays. Intersection of two arrays is an array with elements common in both the original arraysAlgorithmStep 1: Import numpy. Step 2: Define two numpy arrays. Step 3: Find intersection between the arrays using the numpy.intersect1d() function. Step 4: Print the array of intersecting elements.Example Codeimport numpy as np array_1 = np.array([1,2,3,4,5]) print("Array 1:", array_1) array_2 = np.array([2,4,6,8,10]) print("Array 2:", array_2) intersection = np.intersect1d(array_1, array_2) print("The intersection between the two arrays is:", intersection)OutputArray 1: [1 2 3 4 5] Array 2: [2 4 6 8 10] The intersection between the two arrays is: [2 4]
3K+ Views
To change the tick size using ggplot2, we can use theme function with argument axis.ticks.length. For example, if we have a data frame called df that contains two columns say x and y then the scatterplot between x and y with larger size of tick marks can be created by using the below command −ggplot(df,aes(x,y))+geom_point()+theme(axis.ticks.length=unit(0.8,"inch"))ExampleConsider the below data frame − Live Demox
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