Found 1204 Articles for Numpy

numpy.vander Method in Python

Syed Abeed
Updated on 11-Feb-2022 06:34:18

184 Views

The numpy.vander() method is used to generate a Vandermonde (Vander) matrix. A Vander matrix contains a geometric progression in each row, for example, $$\mathrm{A =\begin{bmatrix}1 & 2 & 4 \1 & 3 & 9 \1 & 5 &25\end{bmatrix} or\: B = \begin{bmatrix}1 & 4 & 16 \1 & 6 &36 \end{bmatrix}}$$SyntaxIts syntax is as follows −numpy.vander(x, N=None, increasing=False)ParametersIt accepts the following parameters −x - This is the input array.N - It is the number of columns in the output. By default, it is None.Increasing - If increasing=True, then the power increases from left to right. If increasing=False, then powers are ... Read More

numpy.triu Method in Python

Syed Abeed
Updated on 11-Feb-2022 06:38:25

346 Views

The numpy.triu() method can be used to get the upper triangle of an array. Its syntax is as follows −Syntaxnumpy.triu(m, k=0)where, m - number of rows in the array.k - It is the diagonal. Use k=0 for the main diagonal. k < 0 is below the main diagonal and k > 0 is above it.It returns a copy of the array after replacing all the elements above the kth diagonal with zero.Example 1Let us consider the following example −# import numpy library import numpy as np # create an input matrix x = np.matrix([[6, 7], [8, 9], [10, 11]]) ... Read More

numpy.tril Method in Python

Syed Abeed
Updated on 11-Feb-2022 06:29:46

223 Views

We can use the numpy.tril() method to get the lower triangle of an array. Its syntax is as followsSyntaxnumpy.tril(m, k=0)where, m - number of rows in the array.k - It is the diagonal. Use k=0 for the main diagonal. k < 0 is below the main diagonal and k > 0 is above it.It returns a copy of the array after replacing all the elements above the k thdiagonal with zero.Example 1Let us consider the following example −# import numpy library import numpy as np # create an input matrix x = np.matrix([[20, 21, 22], [44 ,45, 46], [78, ... Read More

numpy.tri Method in Python

Syed Abeed
Updated on 11-Feb-2022 05:59:23

243 Views

The numpy.tri method can be used to get an array of 1's at and below a given diagonal and 0's elsewhere.Syntaxnumpy.tri(N, M=None, k=0, dtype=)Parametersnumpy.tri accepts the following parameters −N - It defines the number of the rows in an array.M - It defines the number of columns in an array. By default, it is None.k - Use k = 0, for the main diagonal, while k < 0 is below it and k > 0 is above it.dtype - It is data type of the returned array. By default, it is float.Example 1Let us consider the following example −# import ... Read More

Join a sequence of arrays with stack() over specific axis in Numpy

AmitDiwan
Updated on 10-Feb-2022 10:11:08

316 Views

To join a sequence of arrays, use the numpy.stack() method in Python Numpy. The axis parameter specifies the index of the new axis in the dimensions of the result. If axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.The function returns the stacked array has one more dimension than the input arrays. The axis parameter specifies the index of the new axis in the dimensions of the result. For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.The out parameter, if provided, the destination ... Read More

Create a recarray from a list of records in text form and fetch arrays based on index in Numpy

AmitDiwan
Updated on 10-Feb-2022 10:08:17

216 Views

To create a recarray from a list of records in text form, use the numpy.core.records.fromrecords() method in Python Numpy. The names is set using the "names" parameter. The field names, either specified as a comma-separated string in the form 'col1, col2, col3', or as a list or tuple of strings in the form ['col1', 'col2', 'col3']. An empty list can be used, in that case default field names (‘f0’, ‘f1’, …) are used. The datatype is set using the "dtype" parameter.The first parameter is the data in the same field may be heterogeneous - they will be promoted to the ... Read More

Return evenly spaced numbers over a log scale in Numpy

AmitDiwan
Updated on 10-Feb-2022 10:05:53

305 Views

To return evenly spaced numbers on a log scale, use the numpy.logspace() method in Python Numpy. The 1st parameter is the "start" i.e. the start of the sequence. The 2nd parameter is the "end" i.e. the end of the sequence.In linear space, the sequence starts at base ** start (base to the power of start) and ends with base ** stop (see endpoint below). The start is the base ** start is the starting value of the sequence. The stop is the base ** stop is the final value of the sequence, unless endpoint is False. In that case, num ... Read More

Return evenly spaced values within a given interval and step size in Numpy

AmitDiwan
Updated on 10-Feb-2022 10:02:01

667 Views

Create an array with int elements using the numpy.arange() method. The 1st parameter is the "start" i.e. the start of the interval. The 2nd parameter is the "end" i.e. the end of the interval. The 3rd parameter is the step size i.e. the spacing between values. The default step size is 2 here.Values are generated within the half-open interval [start, stop). For integer arguments the function is equivalent to the Python built-in range function, but returns an ndarray rather than a list.The stop is the end of interval. The interval does not include this value, except in some cases where ... Read More

Return evenly spaced values within a given interval in Numpy

AmitDiwan
Updated on 10-Feb-2022 09:59:19

158 Views

Create an array with int elements using the numpy.arange() method. The 1st parameter is the "start" i.e. the start of the interval. The 2nd parameter is the "end" i.e. the end of the interval. The 3rd parameter is the spacing between values. The default step size is 1.Values are generated within the half-open interval [start, stop). For integer arguments the function is equivalent to the Python built-in range function, but returns an ndarray rather than a list.The stop is the end of interval. The interval does not include this value, except in some cases where step is not an integer ... Read More

Create a record array from binary data in Numpy

AmitDiwan
Updated on 10-Feb-2022 09:56:40

470 Views

To create a record array from binary data, use the numpy.core.records.fromstring() method in Python Numpy. We have used the tobytes() method for binary data.The first parameter is the datastring i.e. the buffer of binary data. The function returns the record array view into the data in datastring. This will be readonly if datastring is readonly. The offset parameter is the position in the buffer to start reading from. The formats, names, titles, aligned, byteorder parameters, if dtype is None, these arguments are passed to numpy.format_parser to construct a dtype.StepsAt first, import the required library −import numpy as npSet the array type ... Read More

Advertisements