- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 1204 Articles for Numpy
574 Views
To return the upper triangle of an array, use the numpy.triu() method in Python Numpy −The 1st parameter is the input arrayThe 2nd parameter is the 'k' i.e. the diagonal above which to zero elements.Here, k = 0 (the default) is the main diagonal, k < 0 is below it and k > 0 is above.' Array. The k = 1 value is to zero the main diagonal as well. The function returns a copy of an array with the elements below the k-th diagonal zeroed. For arrays with ndim exceeding 2, triu will apply to the final two axes.StepsAt ... Read More
424 Views
To return the upper triangle of an array, use the numpy.triu() method in Python Numpy −The 1st parameter is the input arrayThe 2nd parameter is the 'k' i.e. the diagonal above which to zero elements.Here, k = 0 (the default) is the main diagonal, k < 0 is below it and k > 0 is above. The function returns a copy of an array with the elements below the k-th diagonal zeroed. For arrays with ndim exceeding 2, triu will apply to the final two axes.StepsAt first, import the required library −import numpy as npCreate a 2d array −arr = ... Read More
235 Views
To create a record array from a (flat) list of array, use the numpy.core.records.fromarrays() method in Python Numpy. It returns the record array consisting of given arrayList columns.The first parameter is a List of array-like objects (such as lists, tuples, and ndarrays). The dtype is the valid dtype for all arrays. 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 npCreate a new array using the numpy.array() method −arr1 = np.array([[5, 10, 15], [20, 25, 30]]) arr2 = np.array([[9, 18, ... Read More
3K+ Views
To expand the shape of an array, use the numpy.expand_dims() method. Insert a new array that will appear at the axis position in the expanded array shape. The function returns the View of the input array with the number of dimensions increased.NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more. It supports a wide range of hardware and computing platforms, and plays well with distributed, GPU, and sparse array libraries.StepsAt first, import the required library −import numpy as npCreating an array using the array() method −arr = np.array([5, 10, 15, 20, 25, 30])Display the ... Read More
241 Views
To unpack elements of a uint8 array into a binary-valued output array, use the numpy.unpackbits() method in Python Numpy. The result is binary-valued (0 or 1). The axis is the dimension over which bit-unpacking is done. The axis is set using the "axis" parameter.Each element of the input array represents a bit-field that should be unpacked into a binary-valued output array. The shape of the output array is either 1-D (if axis is None) or the same shape as the input array with unpacking done along the axis specified.The axis is the dimension over which bit-unpacking is done. None implies ... Read More
91 Views
To pack the elements of a binary-valued array into bits in a uint8 array, use the numpy.packbits() method in Python Numpy. The result is padded to full bytes by inserting zero bits at the end. The axis is set using the axis parameter. The axis is the dimension over which bit-packing is done. We have set axis 1.The axis is the dimension over which bit-packing is done. None implies packing the flattened array. The bitorder is the order of the input bits. ‘big’ will mimic bin(val), [0, 0, 0, 0, 0, 0, 1, 1] ⇒ 3 = 0b00000011, 'little' will ... Read More
114 Views
To pack the elements of a binary-valued array into bits in a uint8 array, use the numpy.packbits() method in Python Numpy. The result is padded to full bytes by inserting zero bits at the end. The axis is set using the axis parameter. The axis is the dimension over which bit-packing is done.The axis is the dimension over which bit-packing is done. None implies packing the flattened array. The bitorder is the order of the input bits. ‘big’ will mimic bin(val), [0, 0, 0, 0, 0, 0, 1, 1] ⇒ 3 = 0b00000011, 'little' will reverse the order so [1, ... Read More
583 Views
To compute the bit-wise NOT of a boolean array, use the numpy.bitwise_not() method in Python Numpy. Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ˜.The where parameter is the condition broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.StepsAt first, import ... Read More
116 Views
To compute the bit-wise OR of two 1D arrays element-wise, use the numpy.bitwise_xor() method in Python Numpy. Computes the bit-wise XOR of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ^.The 1st and 2nd parameter are the arrays, only integer and boolean types are handled. If x1.shape != x2.shape, they must be broadcastable to a common shape.The where parameter is the condition broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original ... Read More
179 Views
To return the upper triangle of an array, use the numpy.triu() method in Python Numpy. The 1st parameter is the input array. The function returns a copy of an array with the elements below the kth diagonal zeroed. For arrays with ndim exceeding 2, triu will apply to the final two axes.StepsAt first, import the required library −import numpy as npCreate a 2d array −arr = np.array([[36, 36, 78, 88], [92, 81, 98, 45], [22, 67, 54, 69 ], [69, 80, 80, 99]])Displaying our array −print("Array...", arr)Get the datatype −print("Array datatype...", arr.dtype) Get the dimensions of the Array −print("Array Dimensions...", ... Read More