diff --git a/src/impl_methods.rs b/src/impl_methods.rs
index 2170a8d93..a54e512d1 100644
--- a/src/impl_methods.rs
+++ b/src/impl_methods.rs
@@ -815,6 +815,24 @@ impl ArrayRef
{
unsafe { self.get_ptr(index).map(|ptr| &*ptr) }
}
+
+ /// Return `true` if the index is within the array bounds.
+ ///
+ /// ```
+ /// use ndarray::arr2;
+ ///
+ /// let a = arr2(&[[1., 2.],
+ /// [3., 4.]]);
+ ///
+ /// assert!(a.contains((0, 1)));
+ /// assert!(!a.contains((2, 0)));
+ /// assert!(!a.contains((0, 2)));
+ /// ```
+ pub fn contains(&self, index: I) -> bool
+ where I: NdIndex
+ {
+ index.index_checked(self._dim(), self._strides()).is_some()
+ }
}
impl RawRef