8000 DOC: Use official MATLAB spelling in numpy-for-matlab-users.rst (gh-1… · numpy/numpy@9e8c5d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e8c5d6

Browse files
DOC: Use official MATLAB spelling in numpy-for-matlab-users.rst (gh-17215)
* remove (R) from all MATLAB mentions except the first * Update doc/source/user/numpy-for-matlab-users.rst update the MATLAB case L53 Co-authored-by: Eric Wieser <wieser.eric@gmail.com> * change case of all M/matlab to MATLAB * Update doc/source/user/numpy-for-matlab-users.rst replace (R) in reference to Mathworks reference Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
1 parent db86687 commit 9e8c5d6

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

doc/source/user/numpy-for-matlab-users.rst

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
.. _numpy-for-matlab-users:
22

33
======================
4-
NumPy for Matlab users
4+
NumPy for MATLAB users
55
======================
66

77
Introduction
88
============
99

1010
MATLAB® and NumPy/SciPy have a lot in common. But there are many
1111
differences. NumPy and SciPy were created to do numerical and scientific
12-
computing in the most natural way with Python, not to be MATLAB® clones.
12+
computing in the most natural way with Python, not to be MATLAB clones.
1313
This page is intended to be a place to collect wisdom about the
14-
differences, mostly for the purpose of helping proficient MATLAB® users
14+
differences, mostly for the purpose of helping proficient MATLAB users
1515
become proficient NumPy and SciPy users.
1616

1717
.. raw:: html
@@ -25,7 +25,7 @@ Some Key Differences
2525

2626
.. list-table::
2727

28-
* - In MATLAB®, the basic data type is a multidimensional array of
28+
* - In MATLAB, the basic data type is a multidimensional array of
2929
double precision floating point numbers. Most expressions take such
3030
arrays and return such arrays. Operations on the 2-D instances of
3131
these arrays are designed to act more or less like matrix operations
@@ -36,24 +36,24 @@ Some Key Differences
3636
(though for matrix multiplication, one can use the ``@`` operator
3737
in python 3.5 and above).
3838

39-
* - MATLAB® uses 1 (one) based indexing. The initial element of a
39+
* - MATLAB uses 1 (one) based indexing. The initial element of a
4040
sequence is found using a(1).
4141
:ref:`See note INDEXING <numpy-for-matlab-users.notes>`
4242
- Python uses 0 (zero) based indexing. The initial element of a
4343
sequence is found using a[0].
4444

45-
* - MATLAB®'s scripting language was created for doing linear algebra.
45+
* - MATLAB's scripting language was created for doing linear algebra.
4646
The syntax for basic matrix operations is nice and clean, but the API
4747
for adding GUIs and making full-fledged applications is more or less
4848
an afterthought.
4949
- NumPy is based on Python, which was designed from the outset to be
50-
an excellent general-purpose programming language. While Matlab's
50+
an excellent general-purpose programming language. While MATLAB's
5151
syntax for some array manipulations is more compact than
5252
NumPy's, NumPy (by virtue of being an add-on to Python) can do many
53-
things that Matlab just cannot, for instance dealing properly with
53+
things that MATLAB just cannot, for instance dealing properly with
5454
stacks of matrices.
5555

56-
* - In MATLAB®, arrays have pass-by-value semantics, with a lazy
56+
* - In MATLAB, arrays have pass-by-value semantics, with a lazy
5757
copy-on-write scheme to prevent actually creating copies until they
5858
are actually needed. Slice operations copy parts of the array.
5959
- In NumPy arrays have pass-by-reference semantics. Slice operations
@@ -158,7 +158,7 @@ There are pros and cons to using both:
158158

159159
- ``matrix``
160160

161-
- ``:\\`` Behavior is more like that of MATLAB® matrices.
161+
- ``:\\`` Behavior is more like that of MATLAB matrices.
162162
- ``<:(`` Maximum of two-dimensional. To hold three-dimensional data you
163163
need ``array`` or perhaps a Python list of ``matrix``.
164164
- ``<:(`` Minimum of two-dimensional. You cannot have vectors. They must be
@@ -183,7 +183,7 @@ deprecate ``matrix`` eventually.
183183
Table of Rough MATLAB-NumPy Equivalents
184184
=======================================
185185

186-
The table below gives rough equivalents for some common MATLAB®
186+
The table below gives rough equivalents for some common MATLAB
187187
expressions. **These are not exact equivalents**, but rather should be
188188
taken as hints to get you going in the right direction. For more detail
189189
read the built-in documentation on the NumPy functions.
@@ -272,7 +272,7 @@ Linear Algebra Equivalents
272272
* - ``size(a,n)``
273273
- ``a.shape[n-1]``
274274
- get the number of elements of the n-th dimension of array ``a``. (Note
275-
that MATLAB® uses 1 based indexing while Python uses 0 based indexing,
275+
that MATLAB uses 1 based indexing while Python uses 0 based indexing,
276276
See note :ref:`INDEXING <numpy-for-matlab-users.notes>`)
277277

278278
* - ``[ 1 2 3; 4 5 6 ]``
@@ -356,7 +356,7 @@ Linear Algebra Equivalents
356356

357357
* - ``(a>0.5)``
358358
- ``(a>0.5)``
359-
- matrix whose i,jth element is (a_ij > 0.5). The Matlab result is an
359+
- matrix whose i,jth element is (a_ij > 0.5). The MATLAB result is an
360360
array of 0s and 1s. The NumPy result is an array of the boolean
361361
values ``False`` and ``True``.
362362

@@ -395,7 +395,7 @@ Linear Algebra Equivalents
395395
* - ``y=x(:)``
396396
- ``y = x.flatten()``
397397
- turn array into vector (note that this forces a copy). To obtain the
398-
same data ordering as in Matlab, use ``x.flatten('F')``.
398+
same data ordering as in MATLAB, use ``x.flatten('F')``.
399399

400400
* - ``1:10``
401401
- ``arange(1.,11.)`` or ``r_[1.:11.]`` or ``r_[1:10:10j]``
@@ -475,7 +475,7 @@ Linear Algebra Equivalents
475475

476476
* - ``max(max(a))``
477477
- ``a.max()``
478-
- maximum element of ``a`` (with ndims(a)<=2 for matlab)
478+
- maximum element of ``a`` (with ndims(a)<=2 for MATLAB)
479479

480480
* - ``max(a)``
481481
- ``a.max(0)``
@@ -539,7 +539,7 @@ Linear Algebra Equivalents
539539

540540
* - ``chol(a)``
541541
- ``linalg.cholesky(a).T``
542-
- cholesky factorization of a matrix (``chol(a)`` in matlab returns an
542+
- cholesky factorization of a matrix (``chol(a)`` in MATLAB returns an
543543
upper triangular matrix, but ``linalg.cholesky(a)`` returns a lower
544544
triangular matrix)
545545

@@ -561,7 +561,7 @@ Linear Algebra Equivalents
561561

562562
* - ``[L,U,P]=lu(a)``
563563
- ``L,U = scipy.linalg.lu(a)`` or ``LU,P=scipy.linalg.lu_factor(a)``
564-
- LU decomposition (note: P(Matlab) == transpose(P(numpy)) )
564+
- LU decomposition (note: P(MATLAB) == transpose(P(numpy)) )
565565

566566
* - ``conjgrad``
567567
- ``scipy.sparse.linalg.cg``
@@ -613,7 +613,7 @@ but the commands ``help`` and ``source`` will usually list the filename
613613
where the function is located. Python also has an ``inspect`` module (do
614614
``import inspect``) which provides a ``getfile`` that often works.
615615

616-
\ **INDEXING**: MATLAB® uses one based indexing, so the initial element
616+
\ **INDEXING**: MATLAB uses one based indexing, so the initial element
617617
of a sequence has index 1. Python uses zero based indexing, so the
618618
initial element of a sequence has index 0. Confusion and flamewars arise
619619
because each has advantages and disadvantages. One based indexing is
@@ -623,7 +623,7 @@ indexing <https://groups.google.com/group/comp.lang.python/msg/1bf4d925dfbf368?q
623623
See also `a text by prof.dr. Edsger W.
624624
Dijkstra <https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html>`__.
625625

626-
\ **RANGES**: In MATLAB®, ``0:5`` can be used as both a range literal
626+
\ **RANGES**: In MATLAB, ``0:5`` can be used as both a range literal
627627
and a 'slice' index (inside parentheses); however, in Python, constructs
628628
like ``0:5`` can *only* be used as a slice index (inside square
629629
brackets). Thus the somewhat quirky ``r_`` object was created to allow
@@ -632,46 +632,46 @@ numpy to have a similarly terse range construction mechanism. Note that
632632
*indexed* using square brackets, which allows the use of Python's slice
633633
syntax in the arguments.
634634

635-
\ **LOGICOPS**: & or \| in NumPy is bitwise AND/OR, while in Matlab &
635+
\ **LOGICOPS**: & or \| in NumPy is bitwise AND/OR, while in MATLAB &
636636
and \| are logical AND/OR. The difference should be clear to anyone with
637637
significant programming experience. The two can appear to work the same,
638-
but there are important differences. If you would have used Matlab's &
638+
but there are important differences. If you would have used MATLAB's &
639639
or \| operators, you should use the NumPy ufuncs
640-
logical\_and/logical\_or. The notable differences between Matlab's and
640+
logical\_and/logical\_or. The notable differences between MATLAB's and
641641
NumPy's & and \| operators are:
642642

643643
- Non-logical {0,1} inputs: NumPy's output is the bitwise AND of the
644-
inputs. Matlab treats any non-zero value as 1 and returns the logical
645-
AND. For example (3 & 4) in NumPy is 0, while in Matlab both 3 and 4
644+
inputs. MATLAB treats any non-zero value as 1 and returns the logical
645+
AND. For example (3 & 4) in NumPy is 0, while in MATLAB both 3 and 4
646646
are considered logical true and (3 & 4) returns 1.
647647

648648
- Precedence: NumPy's & operator is higher precedence than logical
649-
operators like < and >; Matlab's is the reverse.
649+
operators like < and >; MATLAB's is the reverse.
650650

651651
If you know you have boolean arguments, you can get away with using
652652
NumPy's bitwise operators, but be careful with parentheses, like this: z
653653
= (x > 1) & (x < 2). The absence of NumPy operator forms of logical\_and
654654
and logical\_or is an unfortunate consequence of Python's design.
655655

656-
**RESHAPE and LINEAR INDEXING**: Matlab always allows multi-dimensional
656+
**RESHAPE and LINEAR INDEXING**: MATLAB always allows multi-dimensional
657657
arrays to be accessed using scalar or linear indices, NumPy does not.
658-
Linear indices are common in Matlab programs, e.g. find() on a matrix
658+
Linear indices are common in MATLAB programs, e.g. find() on a matrix
659659
returns them, whereas NumPy's find behaves differently. When converting
660-
Matlab code it might be necessary to first reshape a matrix to a linear
660+
MATLAB code it might be necessary to first reshape a matrix to a linear
661661
sequence, perform some indexing operations and then reshape back. As
662662
reshape (usually) produces views onto the same storage, it should be
663663
possible to do this fairly efficiently. Note that the scan order used by
664-
reshape in NumPy defaults to the 'C' order, whereas Matlab uses the
664+
reshape in NumPy defaults to the 'C' order, whereas MATLAB uses the
665665
Fortran order. If you are simply converting to a linear sequence and
666-
back this doesn't matter. But if you are converting reshapes from Matlab
667-
code which relies on the scan order, then this Matlab code: z =
666+
back this doesn't matter. But if you are converting reshapes from MATLAB
667+
code which relies on the scan order, then this MATLAB code: z =
668668
reshape(x,3,4); should become z = x.reshape(3,4,order='F').copy() in
669669
NumPy.
670670

671671
Customizing Your Environment
672672
============================
673673

674-
In MATLAB® the main tool available to you for customizing the
674+
In MATLAB the main tool available to you for customizing the
675675
environment is to modify the search path with the locations of your
676676
favorite functions. You can put such customizations into a startup
677677
script that MATLAB will run on startup.
@@ -685,7 +685,7 @@ NumPy, or rather Python, has similar facilities.
685685
interpreter is started, define the ``PYTHONSTARTUP`` environment
686686
variable to contain the name of your startup script.
687687

688-
Unlike MATLAB®, where anything on your path can be called immediately,
688+
Unlike MATLAB, where anything on your path can be called immediately,
689689
with Python you need to first do an 'import' statement to make functions
690690
in a particular file accessible.
691691

@@ -712,7 +712,7 @@ this is just an example, not a statement of "best practices"):
712712
Links
713713
=====
714714

715-
See http://mathesaurus.sf.net/ for another MATLAB®/NumPy
715+
See http://mathesaurus.sf.net/ for another MATLAB/NumPy
716716
cross-reference.
717717

718718
An extensive list of tools for scientific work with python can be

0 commit comments

Comments
 (0)
0