\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Arshdeep} \pdfinfo{ /Title (numpy.pdf) /Creator (Cheatography) /Author (Arshdeep) /Subject (Numpy Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{277AA3} \definecolor{LightBackground}{HTML}{F1F6F9} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Numpy Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Arshdeep} via \textcolor{DarkBackground}{\uline{cheatography.com/201979/cs/42960/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Arshdeep \\ \uline{cheatography.com/arshdeep} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 6th April, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Slicing}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Defitinition} & Array slicing allows you to extract specific parts of an array. It works similarly to list slicing in Python. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Example & `arr = np.array({[}0, 1, 2, 3, 4, 5{]})` \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} Slicing syntax & arr{[}start:stop:step{]} \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} Basic slicing & `slice\_1 = arr{[}1:4{]} \# {[}1, 2, 3{]} \{\{nl\}\}slice\_2 = arr{[}:3{]} \# {[}0, 1, 2{]} \{\{nl\}\}slice\_3 = arr{[}3:{]} \# {[}3, 4, 5{]}` \tn % Row Count 13 (+ 5) % Row 4 \SetRowColor{LightBackground} Negative indexing & `slice\_4 = arr{[}-3:{]} \# {[}3, 4, 5{]} \{\{nl\}\}slice\_5 = arr{[}:-2{]} \# {[}0, 1, 2{]}` \tn % Row Count 16 (+ 3) % Row 5 \SetRowColor{white} Step slicing & `slice\_6 = arr{[}::2{]} \# {[}0, 2, 4{]} \{\{nl\}\}slice\_7 = arr{[}1::2{]} \# {[}1, 3, 5{]}` \tn % Row Count 19 (+ 3) % Row 6 \SetRowColor{LightBackground} Reverse array & `slice\_8 = arr{[}::-1{]} \# {[}5, 4, 3, 2, 1, 0{]}` \tn % Row Count 21 (+ 2) % Row 7 \SetRowColor{white} Slicing 2D arrays & `arr\_2d = np.array({[}{[}1, 2, 3{]}, {[}4, 5, 6{]}, {[}7, 8, 9{]}{]}) \{\{nl\}\}slice\_9 = arr\_2d{[}:2, 1:{]} \# {[}{[}2, 3{]}, {[}5, 6{]}{]}` \tn % Row Count 25 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Performance Tips and Tricks}} \tn % Row 0 \SetRowColor{LightBackground} Vectorization & Utilize NumPy's built-in vectorized operations whenever possible. These operations are optimized and significantly faster than equivalent scalar operations. \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Avoiding Loops & Minimize the use of Python loops when working with NumPy arrays. Instead, try to express operations as array operations. Loops in Python can be slow compared to vectorized operations. \tn % Row Count 15 (+ 8) % Row 2 \SetRowColor{LightBackground} Use Broadcasting & Take advantage of NumPy's broadcasting rules to perform operations on arrays of different shapes efficiently. Broadcasting allows NumPy to work with arrays of different sizes without making unnecessary copies of data. \tn % Row Count 24 (+ 9) % Row 3 \SetRowColor{white} Avoid Copies & Be mindful of unnecessary array copies, especially when working with large datasets. NumPy arrays share memory when possible, but certain operations may create copies, which can impact performance and memory usage. \tn % Row Count 33 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Performance Tips and Tricks (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Use In-Place Operations & Whenever feasible, use in-place operations (+=, *=, etc.) to modify arrays without creating new ones. This reduces memory overhead and can improve performance. \tn % Row Count 7 (+ 7) % Row 5 \SetRowColor{white} Memory Layout & Understand how memory layout affects performance, especially for large arrays. NumPy arrays can be stored in different memory orders (C-order vs. Fortran-order). Choosing the appropriate memory layout can sometimes lead to better performance, especially when performing operations along specific axes. \tn % Row Count 20 (+ 13) % Row 6 \SetRowColor{LightBackground} Data Types & Choose appropriate data types for your arrays to minimize memory usage and improve performance. Using smaller data types (e.g., np.float32 instead of np.float64) can reduce memory overhead and may lead to faster computations, especially on platforms with limited memory bandwidth. \tn % Row Count 32 (+ 12) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Performance Tips and Tricks (cont)}} \tn % Row 7 \SetRowColor{LightBackground} NumExpr and Numba & Consider using specialized libraries like NumExpr or Numba for performance-critical sections of your code. These libraries can often provide significant speedups by compiling expressions or functions to native machine code. \tn % Row Count 9 (+ 9) % Row 8 \SetRowColor{white} Parallelism & NumPy itself doesn't provide built-in parallelism, but you can leverage multi-threading or multi-processing libraries like concurrent.futures or joblib to parallelize certain operations, especially when working with large datasets or computationally intensive tasks. \tn % Row Count 20 (+ 11) % Row 9 \SetRowColor{LightBackground} Profiling & Use profiling tools like cProfile or specialized profilers such as line\_profiler or memory\_profiler to identify performance bottlenecks in your code. Optimizing code based on actual profiling results can lead to more significant performance improvements. \tn % Row Count 31 (+ 11) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Concatenation and Splitting}} \tn % Row 0 \SetRowColor{LightBackground} Concatenation & `array1 = np.array({[}{[}1, 2, 3{]}, {[}4, 5, 6{]}{]}) \{\{nl\}\}array2 = np.array({[}{[}7, 8, 9{]}{]}) \{\{nl\}\}concatenated\_array = \seqsplit{np.concatenate((array1}, array2), axis=0) \{\{nl\}\}\# vertically \{\{nl\}\}print(concatenated\_array)` \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} \seqsplit{numpy.concatenate()} & Concatenates arrays along a specified axis. \tn % Row Count 12 (+ 2) % Row 2 \SetRowColor{LightBackground} numpy.vstack() and numpy.hstack() & Stack arrays vertically and horizontally, respectively. \tn % Row Count 15 (+ 3) % Row 3 \SetRowColor{white} numpy.dstack() & Stack arrays depth-wise. \tn % Row Count 17 (+ 2) % Row 4 \SetRowColor{LightBackground} Splitting & `split\_arrays = \seqsplit{np.split(concatenated\_array}, \{\{nl\}\}{[}2{]}, \{\{nl\}\}axis=0) \{\{nl\}\}\# split after the second row \{\{nl\}\}print(split\_arrays)` \tn % Row Count 23 (+ 6) % Row 5 \SetRowColor{white} numpy.split() & Split an array into multiple sub-arrays along a specified axis. \tn % Row Count 26 (+ 3) % Row 6 \SetRowColor{LightBackground} numpy.hsplit() and numpy.vsplit() & Split arrays horizontally and vertically, respectively. \tn % Row Count 29 (+ 3) % Row 7 \SetRowColor{white} numpy.dsplit() & Split arrays depth-wise. \tn % Row Count 31 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.44 cm} x{4.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Basic Operations}} \tn % Row 0 \SetRowColor{LightBackground} Addition & array1 + array2 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Subtraction & array1 - array2 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Multiplication & array1 * array2 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} Division & array1 / array2 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} Floor Division & array1 // array2 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} Modulus & array1 \% array2 \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} Exponentiation & array1 ** array2 \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} Absolute & np.abs(array) \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} Negative & -array \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} Reciprocal & 1 / array \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} Sum & np.sum(array) \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} Minimum & np.min(array) \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} Maximum & np.max(array) \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} Mean & np.mean(array) \tn % Row Count 14 (+ 1) % Row 14 \SetRowColor{LightBackground} Median & np.median(array) \tn % Row Count 15 (+ 1) % Row 15 \SetRowColor{white} Standard Deviation & np.std(array) \tn % Row Count 17 (+ 2) % Row 16 \SetRowColor{LightBackground} Variance & np.var(array) \tn % Row Count 18 (+ 1) % Row 17 \SetRowColor{white} Dot Product & np.dot(array1, array2) \tn % Row Count 19 (+ 1) % Row 18 \SetRowColor{LightBackground} Cross Product & np.cross(array1, array2) \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{NaN Handling}} \tn % Row 0 \SetRowColor{LightBackground} Identifying NaNs & Use np.isnan() function to check for NaN values in an array. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Removing NaNs & Use np.isnan() to create a boolean mask, then use boolean indexing to select non-NaN values. \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} Replacing NaNs & Use np.nan\_to\_num() to replace NaNs with a specified value. Use np.nanmean(), np.nanmedian(), etc., to compute mean, median, etc., ignoring NaNs. \tn % Row Count 15 (+ 7) % Row 3 \SetRowColor{white} Interpolating NaNs & Sure, here's a short content for "NaN Handling" on your NumPy cheat sheet: NaN Handling: Identifying NaNs: Use np.isnan() function to check for NaN values in an array. Removing NaNs: Use np.isnan() to create a boolean mask, then use boolean indexing to select non-NaN values. Replacing NaNs: Use np.nan\_to\_num() to replace NaNs with a specified value. Use np.nanmean(), np.nanmedian(), etc., to compute mean, median, etc., ignoring NaNs. Interpolating NaNs \tn % Row Count 37 (+ 22) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{NaN Handling (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Ignoring NaNs in Operations & Many NumPy functions have NaN-aware counterparts, like np.nanmean(), np.nansum(), etc., that ignore NaNs in computations. \tn % Row Count 6 (+ 6) % Row 5 \SetRowColor{white} Handling NaNs in Aggregations & Aggregation functions (np.sum(), np.mean(), etc.) typically return NaN if any NaNs are present in the input array. Use skipna=True parameter in pandas DataFrame functions for NaN handling. \tn % Row Count 15 (+ 9) % Row 6 \SetRowColor{LightBackground} Dealing with NaNs in Linear Algebra & NumPy's linear algebra functions (np.linalg.inv(), np.linalg.solve(), etc.) handle NaNs by raising LinAlgError. \tn % Row Count 21 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Broadcasting}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Broadcasting is a powerful feature in NumPy that allows arrays of different shapes to be combined in arithmetic operations.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{When operating on arrays of different shapes, NumPy automatically broadcasts the smaller array across the larger array so that they have compatible shapes.} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{This eliminates the need for explicit looping over array elements, making code more concise and efficient.} \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Broadcasting is particularly useful for performing operations between arrays of different dimensions or sizes without needing to reshape them explicitly.} \tn % Row Count 14 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Mathematical Functions}} \tn % Row 0 \SetRowColor{LightBackground} Definition & NumPy provides a wide range of mathematical functions that operate element-wise on arrays, allowing for efficient computation across large datasets. \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} Trigonometric Functions & np.sin(), np.cos(), np.tan(), np.arcsin(), np.arccos(), np.arctan() \tn % Row Count 12 (+ 4) % Row 2 \SetRowColor{LightBackground} Hyperbolic Functions & np.sinh(), np.cosh(), np.tanh(), np.arcsinh(), np.arccosh(), np.arctanh() \tn % Row Count 16 (+ 4) % Row 3 \SetRowColor{white} Exponential and Logarithmic Functions & np.exp(), np.log(), np.log2(), np.log10() \tn % Row Count 19 (+ 3) % Row 4 \SetRowColor{LightBackground} Rounding & np.round(), np.floor(), np.ceil(), np.trunc() \tn % Row Count 22 (+ 3) % Row 5 \SetRowColor{white} Absolute Value & np.abs() \tn % Row Count 23 (+ 1) % Row 6 \SetRowColor{LightBackground} Factorial and Combinations & np.factorial(), np.comb() \tn % Row Count 25 (+ 2) % Row 7 \SetRowColor{white} Gamma and Beta Functions & np.gamma(), np.beta() \tn % Row Count 27 (+ 2) % Row 8 \SetRowColor{LightBackground} Sum, Mean, Median & np.sum(), np.mean(), np.median() \tn % Row Count 29 (+ 2) % Row 9 \SetRowColor{white} Standard Deviation, Variance & np.std(), np.var() \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Mathematical Functions (cont)}} \tn % Row 10 \SetRowColor{LightBackground} Matrix Operations & np.dot(), np.inner(), np.outer(), np.cross() \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} Eigenvalues and Eigenvectors & np.linalg.eig(), np.linalg.eigh(), np.linalg.eigvals() \tn % Row Count 6 (+ 3) % Row 12 \SetRowColor{LightBackground} Matrix Decompositions & np.linalg.svd(), np.linalg.qr(), \seqsplit{np.linalg.cholesky()} \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.8 cm} x{5.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Creation}} \tn % Row 0 \SetRowColor{LightBackground} numpy.array() & Create an array from a Python list or tuple. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Example & `arr = np.array({[}1, 2, 3{]})` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} numpy.zeros() & Create an array filled with zeros. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Example & `zeros\_arr = np.zeros((3, 3))` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} numpy.ones() & Create an array filled with ones. \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Example & `ones\_arr = np.ones((2, 2))` \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{numpy.arange()} & Create an array with a range of values. \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} Example & `range\_arr = np.arange(0, 10, 2) \# array({[}0, 2, 4, 6, 8{]})` \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} \seqsplit{numpy.linspace()} & Create an array with evenly spaced values. \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} Example & `linspace\_arr = np.linspace(0, 10, 5) \# array({[} 0., 2.5, 5., 7.5, 10.{]})` \tn % Row Count 22 (+ 3) % Row 10 \SetRowColor{LightBackground} numpy.eye() & Create an identity matrix. \tn % Row Count 23 (+ 1) % Row 11 \SetRowColor{white} Example & `identity\_mat = np.eye(3)` \tn % Row Count 24 (+ 1) % Row 12 \SetRowColor{LightBackground} \seqsplit{numpy.random.rand()} & Create an array with random values from a uniform distribution. \tn % Row Count 27 (+ 3) % Row 13 \SetRowColor{white} Example & `random\_arr = np.random.rand(2, 2)` \tn % Row Count 29 (+ 2) % Row 14 \SetRowColor{LightBackground} \seqsplit{numpy.random.randn()} & Create an array with random values from a standard normal distribution. \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.8 cm} x{5.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Creation (cont)}} \tn % Row 15 \SetRowColor{LightBackground} Example & `random\_normal\_arr = np.random.randn(2, 2)` \tn % Row Count 2 (+ 2) % Row 16 \SetRowColor{white} \seqsplit{numpy.random.randint()} & Create an array with random integers. \tn % Row Count 4 (+ 2) % Row 17 \SetRowColor{LightBackground} Example & `random\_int\_arr = np.random.randint(0, 10, size=(2, 2))` \tn % Row Count 7 (+ 3) % Row 18 \SetRowColor{white} numpy.full() & Create an array filled with a specified value. \tn % Row Count 9 (+ 2) % Row 19 \SetRowColor{LightBackground} Example & `full\_arr = np.full((2, 2), 7)` \tn % Row Count 11 (+ 2) % Row 20 \SetRowColor{white} numpy.empty() & Create an uninitialized array (values are not set, might be arbitrary). \tn % Row Count 14 (+ 3) % Row 21 \SetRowColor{LightBackground} Example & `empty\_arr = np.empty((2, 2))` \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Linear Algebra}} \tn % Row 0 \SetRowColor{LightBackground} Matrix Multiplication & np.dot() or @ operator for matrix multiplication. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Transpose & np.transpose() or .T attribute for transposing a matrix. \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Inverse & np.linalg.inv() for calculating the inverse of a matrix. \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} Determinant & np.linalg.det() for computing the determinant of a matrix. \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} Eigenvalues and Eigenvectors & np.linalg.eig() for computing eigenvalues and eigenvectors. \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} Matrix Decompositions & Functions like np.linalg.qr(), np.linalg.svd(), and np.linalg.cholesky() for various matrix decompositions. \tn % Row Count 20 (+ 5) % Row 6 \SetRowColor{LightBackground} Solving Linear Systems & np.linalg.solve() for solving systems of linear equations. \tn % Row Count 23 (+ 3) % Row 7 \SetRowColor{white} Vectorization & Leveraging NumPy's broadcasting and array operations for efficient linear algebra computations. \tn % Row Count 28 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.6 cm} x{6.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Statistical Functions}} \tn % Row 0 \SetRowColor{LightBackground} mean & Computes the arithmetic mean along a specified axis. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} median & Computes the median along a specified axis. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} average & Computes the weighted average along a specified axis. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} std & Computes the standard deviation along a specified axis. \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} var & Computes the variance along a specified axis. \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} amin & Finds the minimum value along a specified axis. \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} amax & Finds the maximum value along a specified axis. \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} argmin & Returns the indices of the minimum value along a specified axis. \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} argmax & Returns the indices of the maximum value along a specified axis. \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{percentile} & Computes the q-th percentile of the data along a specified axis. \tn % Row Count 20 (+ 2) % Row 10 \SetRowColor{LightBackground} \seqsplit{histogram} & Computes the histogram of a set of data. \tn % Row Count 22 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comparison with Python Lists}} \tn % Row 0 \SetRowColor{LightBackground} Performance & NumPy arrays are faster and more memory efficient compared to Python lists, especially for large datasets. This is because NumPy arrays are stored in contiguous blocks of memory and have optimized functions for mathematical operations, whereas Python lists are more flexible but slower due to their dynamic nature. \tn % Row Count 13 (+ 13) % Row 1 \SetRowColor{white} Vectorized Operations & NumPy allows for vectorized operations, which means you can perform operations on entire arrays without the need for explicit looping. This leads to concise and efficient code compared to using loops with Python lists. \tn % Row Count 22 (+ 9) % Row 2 \SetRowColor{LightBackground} \seqsplit{Multidimensional} Arrays & NumPy supports multidimensional arrays, whereas Python lists are limited to one-dimensional arrays or nested lists, which can be less intuitive for handling multi-dimensional data. \tn % Row Count 30 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comparison with Python Lists (cont)}} \tn % Row 3 \SetRowColor{LightBackground} Broadcasting & NumPy arrays support broadcasting, which enables operations between arrays of different shapes and sizes. In contrast, performing similar operations with Python lists would require explicit looping or list comprehensions. \tn % Row Count 9 (+ 9) % Row 4 \SetRowColor{white} Type Stability & NumPy arrays have a fixed data type, which leads to better performance and memory efficiency. Python lists can contain elements of different types, leading to potential type conversion overhead. \tn % Row Count 17 (+ 8) % Row 5 \SetRowColor{LightBackground} Rich Set of Functions & NumPy provides a wide range of mathematical and statistical functions optimized for arrays, whereas Python lists require manual implementation or the use of external libraries for similar functionality. \tn % Row Count 26 (+ 9) % Row 6 \SetRowColor{white} Memory Usage & NumPy arrays typically consume less memory compared to Python lists, especially for large datasets, due to their fixed data type and efficient storage format. \tn % Row Count 33 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comparison with Python Lists (cont)}} \tn % Row 7 \SetRowColor{LightBackground} Indexing and Slicing & NumPy arrays offer more powerful and convenient indexing and slicing capabilities compared to Python lists, making it easier to manipulate and access specific elements or subarrays. \tn % Row Count 8 (+ 8) % Row 8 \SetRowColor{white} Parallel Processing & NumPy operations can leverage parallel processing capabilities of modern CPUs through libraries like Intel MKL or OpenBLAS, resulting in significant performance gains for certain operations compared to Python lists. \tn % Row Count 17 (+ 9) % Row 9 \SetRowColor{LightBackground} \seqsplit{Interoperability} & NumPy arrays can be easily integrated with other scientific computing libraries in Python ecosystem, such as SciPy, Pandas, and Matplotlib, allowing seamless data exchange and interoperability. \tn % Row Count 25 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Masked Arrays}} \tn % Row 0 \SetRowColor{LightBackground} Why? & Masked arrays in NumPy allow you to handle missing or invalid data efficiently. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} What are Masked Arrays? & Masked arrays are arrays with a companion boolean mask array, where elements that are marked as "masked" are ignored during computations. \tn % Row Count 10 (+ 6) % Row 2 \SetRowColor{LightBackground} Creating Masked Arrays & You can create masked arrays using the numpy.ma.masked\_array function, specifying the data array and the mask array. \tn % Row Count 16 (+ 6) % Row 3 \SetRowColor{white} Masking & Masking is the process of marking certain elements of an array as invalid or missing. You can manually create masks or use functions like numpy.ma.masked\_where to create masks based on conditions. \tn % Row Count 25 (+ 9) % Row 4 \SetRowColor{LightBackground} Operations with Masked Arrays & Operations involving masked arrays automatically handle masked values by ignoring them in computations. This allows for easy handling of missing data without explicitly removing or replacing them. \tn % Row Count 34 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Masked Arrays (cont)}} \tn % Row 5 \SetRowColor{LightBackground} Masked Array Methods & NumPy provides methods for masked arrays to perform various operations like calculating statistics, manipulating data, and more. These methods are similar to regular array methods but handle masked values appropriately. \tn % Row Count 10 (+ 10) % Row 6 \SetRowColor{white} Applications & Masked arrays are useful in scenarios where datasets contain missing or invalid data points. They are commonly used in scientific computing, data analysis, and handling time series data where missing values are prevalent. \tn % Row Count 20 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Random Number Generation}} \tn % Row 0 \SetRowColor{LightBackground} np.random.rand & Generates random numbers from a uniform distribution over {[}0, 1). \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} np.random.randn & Generates random numbers from a standard normal distribution (mean 0, standard deviation 1). \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} np.random.randint & Generates random integers from a specified low (inclusive) to high (exclusive) range. \tn % Row Count 14 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{np.random.random\_sample} or np.random.random & Generates random floats in the half-open interval {[}0.0, 1.0). \tn % Row Count 18 (+ 4) % Row 4 \SetRowColor{LightBackground} np.random.choice & Generates random samples from a given 1-D array or list. \tn % Row Count 21 (+ 3) % Row 5 \SetRowColor{white} np.random.shuffle & Shuffles the elements of an array in place. \tn % Row Count 24 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{np.random.permutation} & Randomly permutes a sequence or returns a permuted range. \tn % Row Count 27 (+ 3) % Row 7 \SetRowColor{white} np.random.seed & Sets the random seed to ensure reproducibility of results. \tn % Row Count 30 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Filtering Arrays}} \tn % Row 0 \SetRowColor{LightBackground} Filtering Arrays & NumPy provides powerful tools for filtering arrays based on certain conditions. Filtering allows you to select elements from an array that meet specific criteria. \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Syntax & `filtered\_array = array{[}condition{]}` \tn % Row Count 9 (+ 2) % Row 2 \SetRowColor{LightBackground} Example & `import numpy as np \{\{nl\}\}arr = np.array({[}1, 2, 3, 4, 5{]}) \{\{nl\}\}filtered = arr{[}arr \textgreater{} 2{]} \{\{nl\}\}\# Select elements greater than 2 \{\{nl\}\}print(filtered) \{\{nl\}\}\# Output: {[}3 4 5{]}` \tn % Row Count 16 (+ 7) % Row 3 \SetRowColor{white} Combining Conditions & Conditions can be combined using logical operators like \& (and) and | (or). \tn % Row Count 19 (+ 3) % Row 4 \SetRowColor{LightBackground} Example & `arr = np.array({[}1, 2, 3, 4, 5{]}) \{\{nl\}\}filtered = arr{[}(arr \textgreater{} 2) \& (arr \textless{} 5){]} \{\{nl\}\}\# Select elements between 2 and 5 \{\{nl\}\}print(filtered) \{\{nl\}\}\# Output: {[}3 4{]}` \tn % Row Count 26 (+ 7) % Row 5 \SetRowColor{white} Using Functions & NumPy also provides functions like np.where() and np.extract() for more complex filtering. \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Filtering Arrays (cont)}} \tn % Row 6 \SetRowColor{LightBackground} Example & `arr = np.array({[}1, 2, 3, 4, 5{]}) \{\{nl\}\}filtered = np.where(arr \% 2 == 0, arr, 0) \{\{nl\}\}\# Replace odd elements with 0 \{\{nl\}\}print(filtered) \{\{nl\}\}\# Output: {[}0 2 0 4 0{]}` \tn % Row Count 7 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Iteration}} \tn % Row 0 \SetRowColor{LightBackground} For Loops & Iterate over arrays using traditional for loops. This is useful for basic iteration but might not be the most efficient method for large arrays. \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} nditer & The nditer object allows iterating over arrays in a more efficient and flexible way. It provides options to specify the order of iteration, data type casting, and external loop handling. \tn % Row Count 14 (+ 8) % Row 2 \SetRowColor{LightBackground} Flat Iteration & The flat attribute of NumPy arrays returns an iterator that iterates over all elements of the array as if it were a flattened 1D array. This is useful for simple element-wise operations. \tn % Row Count 22 (+ 8) % Row 3 \SetRowColor{white} Broadcasting & When performing operations between arrays of different shapes, NumPy automatically broadcasts the arrays to compatible shapes. Understanding broadcasting rules can help efficiently iterate over arrays without explicit loops. \tn % Row Count 31 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Iteration (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Vectorized Operations & Instead of explicit iteration, utilize NumPy's built-in vectorized operations which operate on entire arrays rather than individual elements. This often leads to faster and more concise code. \tn % Row Count 8 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Reshaping}} \tn % Row 0 \SetRowColor{LightBackground} Array Reshaping & Reshaping arrays in NumPy allows you to change the shape or dimensions of an existing array without changing its data. This is useful for tasks like converting a 1D array into a 2D array or vice versa, or for preparing data for certain operations like matrix multiplication. \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} reshape() & The reshape() function in NumPy allows you to change the shape of an array to a specified shape. \tn % Row Count 14 (+ 4) % Row 2 \SetRowColor{LightBackground} For example: & import numpy as np \{\{nl\}\} \{\{nl\}\}arr = np.array({[}1, 2, 3, 4, 5, 6{]}) \{\{nl\}\}reshaped\_arr = arr.reshape((2, 3)) \tn % Row Count 18 (+ 4) % Row 3 \SetRowColor{white} \seqsplit{Explanation} & This will reshape the array arr into a 2x3 matrix. \tn % Row Count 20 (+ 2) % Row 4 \SetRowColor{LightBackground} resize() & Similar to reshape(), resize() changes the shape of an array, but it also modifies the original array if necessary to accommodate the new shape. \tn % Row Count 25 (+ 5) % Row 5 \SetRowColor{white} Example & `arr = np.array({[}{[}1, 2{]}, {[}3, 4{]}{]}) \{\{nl\}\}resized\_arr = np.resize(arr, (3, 2))` \tn % Row Count 28 (+ 3) % Row 6 \SetRowColor{LightBackground} \seqsplit{Explanation} & If the new shape requires more elements than the original array has, resize() repeats the original array to fill in the new shape. \tn % Row Count 33 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Reshaping (cont)}} \tn % Row 7 \SetRowColor{LightBackground} flatten() & The flatten() method collapses a multi-dimensional array into a 1D array by iterating over all elements in row-major (C-style) order. \tn % Row Count 5 (+ 5) % Row 8 \SetRowColor{white} Example & `arr = np.array({[}{[}1, 2{]}, {[}3, 4{]}{]}) \{\{nl\}\}flattened\_arr = arr.flatten()` \tn % Row Count 8 (+ 3) % Row 9 \SetRowColor{LightBackground} \seqsplit{Explanation} & This will flatten the 2D array into a 1D array. \tn % Row Count 10 (+ 2) % Row 10 \SetRowColor{white} ravel() & Similar to flatten(), ravel() also flattens multi-dimensional arrays into a 1D array, but it returns a view of the original array whenever possible. \tn % Row Count 16 (+ 6) % Row 11 \SetRowColor{LightBackground} Example & `arr = np.array({[}{[}1, 2{]}, {[}3, 4{]}{]}) \{\{nl\}\}raveled\_arr = arr.ravel()` \tn % Row Count 19 (+ 3) % Row 12 \SetRowColor{white} \seqsplit{Explanation} & This method can be more efficient in terms of memory usage than flatten(). \tn % Row Count 22 (+ 3) % Row 13 \SetRowColor{LightBackground} \seqsplit{transpose()} & The transpose() method rearranges the dimensions of an array. For 2D arrays, it effectively swaps rows and columns. \tn % Row Count 26 (+ 4) % Row 14 \SetRowColor{white} Example & `arr = np.array({[}{[}1, 2{]}, {[}3, 4{]}{]}) \{\{nl\}\}transposed\_arr = arr.transpose()` \tn % Row Count 29 (+ 3) % Row 15 \SetRowColor{LightBackground} \seqsplit{Explanation} & This will transpose the 2x2 matrix, swapping rows and columns. \tn % Row Count 32 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Sorting Arrays}} \tn % Row 0 \SetRowColor{LightBackground} np.sort(arr) & Returns a sorted copy of the array. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} arr.sort() & Sorts the array in-place. \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{np.argsort(arr)} & Returns the indices that would sort the array. \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} np.lexsort() & Performs an indirect sort using a sequence of keys. \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{np.sort\_complex(arr)} & Sorts the array of complex numbers based on the real part first, then the imaginary part. \tn % Row Count 12 (+ 4) % Row 5 \SetRowColor{white} \seqsplit{np.partition(arr}, k) & Rearranges the elements in such a way that the kth element will be in its correct position in the sorted array, with all smaller elements to its left and all larger elements to its right. \tn % Row Count 20 (+ 8) % Row 6 \SetRowColor{LightBackground} \seqsplit{np.argpartition(arr}, k) & Returns the indices that would partition the array. \tn % Row Count 23 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Indexing}} \tn % Row 0 \SetRowColor{LightBackground} Single Element Access & Use square brackets {[}{]} to access individual elements of an array by specifying the indices for each dimension. For example, arr{[}0, 1{]} accesses the element at the first row and second column of the array arr. \tn % Row Count 11 (+ 11) % Row 1 \SetRowColor{white} Negative Indexing & Negative indices can be used to access elements from the end of the array. For instance, arr{[}-1{]} accesses the last element of the array arr. \tn % Row Count 18 (+ 7) % Row 2 \SetRowColor{LightBackground} Slice Indexing & NumPy arrays support slicing similar to Python lists. You can use the colon : operator to specify a range of indices. For example, arr{[}1:3{]} retrieves elements from index 1 to index 2 (inclusive) along the first axis. \tn % Row Count 29 (+ 11) % Row 3 \SetRowColor{white} Integer Array Indexing & You can use arrays of integer indices to extract specific elements from an array. For example, arr{[}{[}0, 2, 4{]}{]} retrieves elements at indices 0, 2, and 4 along the first axis. \tn % Row Count 38 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array Indexing (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Boolean Array Indexing (Boolean Masking) & You can use boolean arrays to filter elements from an array based on a condition. For example, arr{[}arr \textgreater{} 0{]} retrieves all elements of arr that are greater than zero. \tn % Row Count 9 (+ 9) % Row 5 \SetRowColor{white} Fancy Indexing & Fancy indexing allows you to select multiple elements from an array using arrays of indices or boolean masks. This method can be used to perform advanced selection operations efficiently. \tn % Row Count 19 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}