numpy.meshgrid() in PythonThe numpy module of Python provides meshgrid() function for creating a rectangular grid with the help of the given 1-D arrays that represent the Matrix indexing or Cartesian indexing. MATLAB somewhat inspires the meshgrid() function. From the coordinate vectors, the meshgrid() function returns the coordinate matrices. In the above figure, the x-axis is ranging from -5 to 5, and the y-axis is ranging from -5 to 5. So, there is a total of 121 points marked in the figure, each with x-coordinate and y-coordinate. For any line parallel to the x-axis, the x-coordinates of the marked points are -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, and 5 respectively. On the other hand, for any line parallel to the y-axis, the y-coordinates of the marked points from bottom to top are -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, and 5 respectively. SyntaxParametersx1, x2,…, xn : array_like This parameter defines the 1-dimensional array, which represents the coordinates of a grid. indexing: {'xy', 'ij'}(optional) This is an optional argument which defines the Cartesian 'xy'(by default) or matrix ('ij') indexing of output. sparse: bool(optional) This parameter is also optional. If we need a sparse grid for conserving memory, we have to set this parameter to True. By default, it is set to False. copy: bool(optional) The aim of this optional argument is that it returns a copy of the original array for conserving memory. By default, it is set to False. If both sparse and copy parameters are set to False, then it will return non-contiguous arrays. In addition, more than one element of a broadcast array can refer to a single memory location. If we need to write into the arrays, then we have to make copies first. ReturnsX1, X2, …, Xn The coordinate length from the coordinate vector is returned from this function. Example 1:Output: array([[1. , 1.25, 1.5 , 1.75, 2. ], [1. , 1.25, 1.5 , 1.75, 2. ], [1. , 1.25, 1.5 , 1.75, 2. ]]) array([[1. , 1. , 1. , 1. , 1. ], [1.5, 1.5, 1.5, 1.5, 1.5], [2. , 2. , 2. , 2. , 2. ]]) In the above code
In the output, two arrays have been shown which contain the coordinate length from the coordinate vectors. Example 2:Output: array([[1. , 1.25, 1.5 , 1.75, 2. ]]) array([[1. ], [1.5], [2. ]]) Example 3:Output: In the above code
In the output, contour lines have been plotted. Example 4:Output: Example 5:Output: Next TopicNumpy.std() |