numpy.in1d() function in Python (original) (raw)
Last Updated : 17 May, 2020
numpy.in1d()
function test whether each element of a 1-D array is also present in a second array and return a boolean array the same length as arr1 that is True where an element of arr1 is in arr2 and False otherwise.
Syntax : numpy.in1d(arr1, arr2, assume_unique = False, invert = False)
Parameters :
arr1 : [array_like] Input array.
arr2 : [array_like] The values against which to test each value of arr1.
assume_unique : [bool, optional] If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False.
invert : [bool, optional] If True, the values in the returned array are inverted. Default is False.Return : [ndarray, bool] The values arr1[in1d] are in arr2.
Code #1 :
import
numpy as geek
arr1
=
geek.array([
0
,
1
,
2
,
3
,
0
,
4
,
5
])
arr2
=
[
0
,
2
,
5
]
gfg
=
geek.in1d(arr1, arr2)
print
(gfg)
Output :
[ True False True False True False True]
Code #2 :
import
numpy as geek
arr1
=
geek.array([
0
,
1
,
2
,
3
,
0
,
4
,
5
])
arr2
=
[
0
,
2
,
5
]
gfg
=
geek.in1d(arr1, arr2, invert
=
True
)
print
(gfg)
Output :
[False True False True False True False]
Similar Reads
- numpy.iinfo() function – Python numpy.iinfo() function shows machine limits for integer types. Syntax : numpy.iinfo(dtype) Parameters : dtype : [integer type, dtype, or instance] The kind of integer data type to get information about. Return : Machine limits for integer types. Code #1 : # Python program explaining # numpy.iinfo() 1 min read
- numpy.intersect1d() function in Python numpy.intersect1d() function find the intersection of two arrays and return the sorted, unique values that are in both of the input arrays. Syntax: numpy.intersect1d(arr1, arr2, assume_unique = False, return_indices = False) Parameters : arr1, arr2 : [array_like] Input arrays. assume_unique : [bool] 1 min read
- numpy.nanstd() function - Python numpy.nanstd() function compute the standard deviation along the specified axis, while ignoring NaNs. Syntax : numpy.nanstd(arr, axis = None, dtype = None, out = None, ddof = 0, keepdims) Parameters : arr : [array_like] Calculate the standard deviation of the non-NaN values. axis : [{int, tuple of i 2 min read
- numpy.i0() function | Python numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev 1 min read
- numpy.interp() function - Python numpy.interp() function returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x. Syntax : numpy.interp(x, xp, fp, left = None, right = None, period = None) Parameters : x : [array_like] The x-coordinates at which to evaluate the 2 min read
- numpy.dtype.kind() function – Python numpy.dtype.kind() function determine the character code by identifying the general kind of data. Syntax : numpy.dtype.kind(type) Parameters : type : [dtype] The input data-type. Return : Return the character code by identifying the general kind of data. Code #1 : # Python program explaining # numpy 1 min read
- numpy.mintypecode() function – Python numpy.mintypecode() function return the character for the minimum-size type to which given types can be safely cast. Syntax : numpy.mintypecode(typechars, typeset = 'GDFgdf', default = 'd') Parameters : typechars : [list of str or array_like] If a list of strings, each string should represent a dtyp 1 min read
- id() function in Python In Python, id() function is a built-in function that returns the unique identifier of an object. The identifier is an integer, which represents the memory address of the object. The id() function is commonly used to check if two variables or objects refer to the same memory location. Python id() Fun 3 min read
- numpy.mask_indices() function | Python numpy.mask_indices() function return the indices to access (n, n) arrays, given a masking function. Syntax : numpy.mask_indices(n, mask_func, k = 0) Parameters : n : [int] The returned indices will be valid to access arrays of shape (n, n). mask_func : [callable] A function whose call signature is s 1 min read
- numpy.ma.ediff1d() function in Python numpy.ma.ediff1d() function return the differences between consecutive elements of an array. Syntax : numpy.ma.ediff1d(arr, to_end = None, to_begin = None) Parameters : arr : [array_like] Input array. to_end : [array_like, optional] Number to append at the end of the returned differences. to_begin : 1 min read