Skip to content

Commit d1bb045

Browse files
committed
Fix end tag, toc and reorder type conversion doc
1 parent ce3f541 commit d1bb045

File tree

1 file changed

+38
-36
lines changed
  • src/doc/ndarray_for_numpy_users

1 file changed

+38
-36
lines changed

src/doc/ndarray_for_numpy_users/mod.rs

+38-36
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! * [Mathematics](#mathematics)
2020
//! * [Array manipulation](#array-manipulation)
2121
//! * [Iteration](#iteration)
22+
//! * [Type conversions](#type-conversions)
2223
//! * [Convenience methods for 2-D arrays](#convenience-methods-for-2-d-arrays)
2324
//!
2425
//! # Similarities
@@ -524,6 +525,42 @@
524525
//! </td></tr>
525526
//! </table>
526527
//!
528+
//! ## Array manipulation
529+
//!
530+
//! NumPy | `ndarray` | Notes
531+
//! ------|-----------|------
532+
//! `a[:] = 3.` | [`a.fill(3.)`][.fill()] | set all array elements to the same scalar value
533+
//! `a[:] = b` | [`a.assign(&b)`][.assign()] | copy the data from array `b` into array `a`
534+
//! `np.concatenate((a,b), axis=1)` | [`concatenate![Axis(1), a, b]`][concatenate!] or [`concatenate(Axis(1), &[a.view(), b.view()])`][concatenate()] | concatenate arrays `a` and `b` along axis 1
535+
//! `np.stack((a,b), axis=1)` | [`stack![Axis(1), a, b]`][stack!] or [`stack(Axis(1), vec![a.view(), b.view()])`][stack()] | stack arrays `a` and `b` along axis 1
536+
//! `a[:,np.newaxis]` or `np.expand_dims(a, axis=1)` | [`a.slice(s![.., NewAxis])`][.slice()] or [`a.insert_axis(Axis(1))`][.insert_axis()] | create an view of 1-D array `a`, inserting a new axis 1
537+
//! `a.transpose()` or `a.T` | [`a.t()`][.t()] or [`a.reversed_axes()`][.reversed_axes()] | transpose of array `a` (view for `.t()` or by-move for `.reversed_axes()`)
538+
//! `np.diag(a)` | [`a.diag()`][.diag()] | view the diagonal of `a`
539+
//! `a.flatten()` | [`use std::iter::FromIterator; Array::from_iter(a.iter().cloned())`][::from_iter()] | create a 1-D array by flattening `a`
540+
//!
541+
//! ## Iteration
542+
//!
543+
//! `ndarray` has lots of interesting iterators/producers that implement the
544+
//! [`NdProducer`](crate::NdProducer) trait, which is a generalization of `Iterator`
545+
//! to multiple dimensions. This makes it possible to correctly and efficiently
546+
//! zip together slices/subviews of arrays in multiple dimensions with
547+
//! [`Zip`] or [`azip!()`]. The purpose of this is similar to
548+
//! [`np.nditer`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nditer.html),
549+
//! but [`Zip`] is implemented and used somewhat differently.
550+
//!
551+
//! This table lists some of the iterators/producers which have a direct
552+
//! equivalent in NumPy. For a more complete introduction to producers and
553+
//! iterators, see [*Loops, Producers, and
554+
//! Iterators*](ArrayBase#loops-producers-and-iterators).
555+
//! Note that there are also variants of these iterators (with a `_mut` suffix)
556+
//! that yield `ArrayViewMut` instead of `ArrayView`.
557+
//!
558+
//! NumPy | `ndarray` | Notes
559+
//! ------|-----------|------
560+
//! `a.flat` | [`a.iter()`][.iter()] | iterator over the array elements in logical order
561+
//! `np.ndenumerate(a)` | [`a.indexed_iter()`][.indexed_iter()] | flat iterator yielding the index along with each element reference
562+
//! `iter(a)` | [`a.outer_iter()`][.outer_iter()] or [`a.axis_iter(Axis(0))`][.axis_iter()] | iterator over the first (outermost) axis, yielding each subview
563+
//!
527564
//! ## Type conversions
528565
//!
529566
//! In `ndarray`, conversions between datatypes are done with `mapv()` by
@@ -614,47 +651,12 @@
614651
//! convert `f32` array to `i32` array with ["saturating" conversion][sat_conv]; care needed because it can be a lossy conversion or result in non-finite values! See [the reference for information][as_typecast].
615652
//!
616653
//! </td></tr>
654+
//! <table>
617655
//!
618656
//! [as_conv]: https://doc.rust-lang.org/rust-by-example/types/cast.html
619657
//! [sat_conv]: https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#fixing-unsoundness-in-casts
620658
//! [as_typecast]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions
621659
//!
622-
//! ## Array manipulation
623-
//!
624-
//! NumPy | `ndarray` | Notes
625-
//! ------|-----------|------
626-
//! `a[:] = 3.` | [`a.fill(3.)`][.fill()] | set all array elements to the same scalar value
627-
//! `a[:] = b` | [`a.assign(&b)`][.assign()] | copy the data from array `b` into array `a`
628-
//! `np.concatenate((a,b), axis=1)` | [`concatenate![Axis(1), a, b]`][concatenate!] or [`concatenate(Axis(1), &[a.view(), b.view()])`][concatenate()] | concatenate arrays `a` and `b` along axis 1
629-
//! `np.stack((a,b), axis=1)` | [`stack![Axis(1), a, b]`][stack!] or [`stack(Axis(1), vec![a.view(), b.view()])`][stack()] | stack arrays `a` and `b` along axis 1
630-
//! `a[:,np.newaxis]` or `np.expand_dims(a, axis=1)` | [`a.slice(s![.., NewAxis])`][.slice()] or [`a.insert_axis(Axis(1))`][.insert_axis()] | create an view of 1-D array `a`, inserting a new axis 1
631-
//! `a.transpose()` or `a.T` | [`a.t()`][.t()] or [`a.reversed_axes()`][.reversed_axes()] | transpose of array `a` (view for `.t()` or by-move for `.reversed_axes()`)
632-
//! `np.diag(a)` | [`a.diag()`][.diag()] | view the diagonal of `a`
633-
//! `a.flatten()` | [`use std::iter::FromIterator; Array::from_iter(a.iter().cloned())`][::from_iter()] | create a 1-D array by flattening `a`
634-
//!
635-
//! ## Iteration
636-
//!
637-
//! `ndarray` has lots of interesting iterators/producers that implement the
638-
//! [`NdProducer`](crate::NdProducer) trait, which is a generalization of `Iterator`
639-
//! to multiple dimensions. This makes it possible to correctly and efficiently
640-
//! zip together slices/subviews of arrays in multiple dimensions with
641-
//! [`Zip`] or [`azip!()`]. The purpose of this is similar to
642-
//! [`np.nditer`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.nditer.html),
643-
//! but [`Zip`] is implemented and used somewhat differently.
644-
//!
645-
//! This table lists some of the iterators/producers which have a direct
646-
//! equivalent in NumPy. For a more complete introduction to producers and
647-
//! iterators, see [*Loops, Producers, and
648-
//! Iterators*](ArrayBase#loops-producers-and-iterators).
649-
//! Note that there are also variants of these iterators (with a `_mut` suffix)
650-
//! that yield `ArrayViewMut` instead of `ArrayView`.
651-
//!
652-
//! NumPy | `ndarray` | Notes
653-
//! ------|-----------|------
654-
//! `a.flat` | [`a.iter()`][.iter()] | iterator over the array elements in logical order
655-
//! `np.ndenumerate(a)` | [`a.indexed_iter()`][.indexed_iter()] | flat iterator yielding the index along with each element reference
656-
//! `iter(a)` | [`a.outer_iter()`][.outer_iter()] or [`a.axis_iter(Axis(0))`][.axis_iter()] | iterator over the first (outermost) axis, yielding each subview
657-
//!
658660
//! ## Convenience methods for 2-D arrays
659661
//!
660662
//! NumPy | `ndarray` | Notes

0 commit comments

Comments
 (0)