numpy.array_equiv() in Python (original) (raw)
Last Updated : 29 Nov, 2018
numpy.array_equiv(arr1, arr2) : This logical function that checks if two arrays have the same elements and shape consistent.
Shape consistent means either they are having the same shape, or one input array can be broadcasted to create the same shape as the other one.
Parameters :
arr1 : [array_like]Input array, we need to test. arr2 : [array_like]Input array, we need to test.
Return :
True, if both arrays are equivalent; otherwise False
Code : Explaining Working
import
numpy as np
arr1
=
np.arange(
4
)
arr2
=
[
7
,
4
,
6
,
7
]
print
(
"arr1 : "
, arr1)
print
(
"arr2 : "
, arr2)
print
(
"\nResult : "
, np.array_equiv(arr1, arr2))
arr1
=
np.arange(
4
)
arr2
=
np.arange(
4
)
print
(
"\n\narr1 : "
, arr1)
print
(
"arr2 : "
, arr2)
print
(
"\nResult : "
, np.array_equiv(arr1, arr2))
arr1
=
np.arange(
4
)
arr2
=
np.arange(
5
)
print
(
"\n\narr1 : "
, arr1)
print
(
"arr2 : "
, arr2)
print
(
"\nResult : "
, np.array_equiv(arr1, arr2))
a
=
np.array_equiv([
1
,
2
], [[
1
,
2
,
1
,
2
], [
1
,
2
,
1
,
2
]])
b
=
np.array_equiv([
1
,
2
], [[
1
,
2
], [
1
,
2
]])
print
(
"\n\na : "
, a)
print
(
"\nb : "
, b)
Output :
arr1 : [0 1 2 3] arr2 : [7, 4, 6, 7]
Result : False
arr1 : [0 1 2 3] arr2 : [0 1 2 3]
Result : True
arr1 : [0 1 2 3] arr2 : [0 1 2 3 4]
Result : False
a : False
b : True
References :
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.array_equiv.html#numpy.array_equiv
.
Similar Reads
- numpy.array_equal() in Python numpy.array_equal(arr1, arr2) : This logical function that checks if two arrays have the same shape and elements. Parameters : arr1 : [array_like]Input array or object whose elements, we need to test. arr2 : [array_like]Input array or object whose elements, we need to test. Return : True, if both ar 1 min read
- NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read
- numpy.asarray() in Python numpy.asarray()function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of lists and arrays. Syntax : numpy.asarray(arr, dtype=None, order=None) Parameters : arr : [array_like] Input data, in any form that can be converted to a 2 min read
- numpy.asfarray() in Python numpy.asfarray()function is used when we want to convert input to a float type array. Input includes scalar, lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. Syntax : numpy.asfarray(arr, dtype=type 'numpy.float64') Parameters : arr : [array_like] Input data, in any for 2 min read
- Boolean Array in NumPy - Python The goal here is to work with Boolean arrays in NumPy, which contain only True or False values. Boolean arrays are commonly used for conditional operations, masking and filtering elements based on specific criteria. For example, given a NumPy array [1, 0, 1, 0, 1], we can create a Boolean array wher 3 min read
- numpy.array_str() in Python numpy.array_str()function is used to represent the data of an array as a string. The data in the array is returned as a single string. This function is similar to array_repr, the difference being that array_repr also returns information on the kind of array and its data type. Syntax : numpy.array_st 2 min read
- numpy.array_repr() in Python numpy.array_repr()function is used to convert an array to a string. Syntax : numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None) Parameters : arr : [array_like] Input array. max_line_width : [int, optional] The maximum number of columns the string should span. Newline cha 2 min read
- Python | Numpy numpy.ndarray.__ne__() With the help of numpy.ndarray.__ne__() method of Numpy, We can find that which element in an array is not equal to the value which is provided in the parameter. It will return you numpy array with boolean type having only values True and False. Syntax: ndarray.__ne__($self, value, /) Return: self!= 1 min read
- numpy.asanyarray() in Python numpy.asanyarray()function is used when we want to convert input to an array but it pass ndarray subclasses through. Input can be scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays. Syntax : numpy.asanyarray(arr, dtype=None, order=None) Parameters : arr : [array_ 2 min read
- numpy.around() in Python numpy.around(arr, decimals = 0, out = None) : This mathematical function helps user to evenly round array elements to the given number of decimals. Parameters : array : [array_like] Input array. decimal : [int, optional] Decimal places we want to round off. Default = 0. In case of -ve decimal, it sp 2 min read