{ "cells": [ { "cell_type": "markdown", "id": "7a9da3e4-a34a-4fd6-983e-983283930b7f", "metadata": {}, "source": [ "![](https://datlinux.com/numpysuperposter.jpg)" ] }, { "cell_type": "markdown", "id": "6d76525d-29d9-4508-afb1-fbceffd83725", "metadata": {}, "source": [ "# About this guide\n", "\n", "This is the companion notebook to the [NUMPY SUPER POSTER](https://datlinux.com/numpy). The most comprehensive \"cheat sheet\" out there. There is no digital version of this poster, it's only available in print (large 24\" x 36\" format). Perfect to pin-up for easy reference. A great gift for the data science nerd.\n", "\n", "*Whilst all care for accuracy was taken, the information provided within this guide comes with absolutely no warranty. This guide is the intellectual property of LM Web Tech. (Australia), © Copyright 2023. Published by FadeOutPrint. Proudly accociated with DAT Linux (datlinux.com/numpy ) -- the data science OS.*" ] }, { "cell_type": "markdown", "id": "9cbb607c-66d1-4e6c-aced-212c91a90cbd", "metadata": {}, "source": [ "# Getting Started\n", "___ " ] }, { "cell_type": "code", "execution_count": 1, "id": "9eef718a-6b05-4b2a-b3cb-c603c24436f3", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "id": "e5329f89-08de-4b47-b1aa-a52ac62186af", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'1.26.0'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.__version__ " ] }, { "cell_type": "code", "execution_count": 3, "id": "71ff8167-fcab-4c02-8f71-1bd379a21eab", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "class: ndarray\n", "shape: (1,)\n", "strides: (8,)\n", "itemsize: 8\n", "aligned: True\n", "contiguous: True\n", "fortran: True\n", "data pointer: 0x55d9fdc244b0\n", "byteorder: little\n", "byteswap: False\n", "type: int64\n" ] } ], "source": [ "a = np.array([1])\n", "np.info(a)" ] }, { "cell_type": "markdown", "id": "91a03fd8-8334-4f80-b330-0587eae7c8c4", "metadata": {}, "source": [ "# Array Basics\n", "___ " ] }, { "cell_type": "markdown", "id": "60fefe5b-2275-4f65-a49f-78260fee207c", "metadata": {}, "source": [ "## Data types:" ] }, { "cell_type": "code", "execution_count": 4, "id": "8e5a4f16-f6b4-4929-beec-98b87925ca61", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dtype([('name1', '2] " ] }, { "cell_type": "code", "execution_count": 86, "id": "5548fbd6-ce9b-4431-bb7c-60a639d39c75", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([2., 3.])" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[a//2==1] # Combining arithmetic with boolean expression" ] }, { "cell_type": "markdown", "id": "98b38137-7709-4619-b3ca-698ea82aef4a", "metadata": {}, "source": [ "# Array Computation\n", "___ " ] }, { "cell_type": "markdown", "id": "05badd33-7c95-4d6b-a032-48e9b0ce4d52", "metadata": {}, "source": [ "## Unary Ufuncs (operating on a single array): " ] }, { "cell_type": "code", "execution_count": 87, "id": "1f4a3228-6bfb-4467-b4fc-daa19702fb5f", "metadata": {}, "outputs": [], "source": [ "a = np.array([1, 2, 3])" ] }, { "cell_type": "code", "execution_count": 88, "id": "f716db2d-21b6-47e5-90fb-150330f6c6af", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3])" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.abs(np.array([-1, 2, -3]))" ] }, { "cell_type": "code", "execution_count": 89, "id": "3b16b550-d33c-4590-a916-2abff04f2ec5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-2., 2., 3.])" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.floor(np.array([-1.3, 2, 3.8]))" ] }, { "cell_type": "code", "execution_count": 90, "id": "8206b443-749f-4411-8732-47a45f798aa6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-1., 2., 4.])" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.rint(np.array([-1.3, 2, 3.8]))" ] }, { "cell_type": "code", "execution_count": 91, "id": "983fc65f-9977-4284-86e7-adb10be6aab8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3., 4., 2.])" ] }, "execution_count": 91, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sqrt(np.array([9, 16, 4]))" ] }, { "cell_type": "code", "execution_count": 92, "id": "62ab87d3-04a9-4615-adc1-31fdbd805788", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([2.71828183, 7.3890561 ])" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.exp(np.array([1, 2]))" ] }, { "cell_type": "code", "execution_count": 93, "id": "9f9f6adb-48c9-4ba1-a81c-c8ddd60d6c4c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([2., 3.])" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.log10(np.array([100, 1000]))" ] }, { "cell_type": "code", "execution_count": 94, "id": "bc698b62-584b-400e-8cd7-8a5e3a00f86a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-1., 1.])" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sign(np.array([-2., 2.5]))" ] }, { "cell_type": "code", "execution_count": 95, "id": "f64116a1-dc8e-4adb-b312-5fb70a2fe3d7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([ 0. , -0.1]), array([ 1., -2.]))" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.modf(np.array([1, -2.1]))" ] }, { "cell_type": "code", "execution_count": 96, "id": "5445ebb9-7280-4fac-9d79-5b66348f8799", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([False, True])" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.isnan(np.array([1, np.nan]))" ] }, { "cell_type": "code", "execution_count": 97, "id": "c1791c32-ee25-4fe3-9bc0-9e6ec33702a4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0. , 0.84147098])" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sin(np.array([0, 1]))" ] }, { "cell_type": "code", "execution_count": 98, "id": "90850d64-508b-426b-a56f-4fceb4965e9f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0. , 1.17520119])" ] }, "execution_count": 98, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sinh(np.array([0, 1]))" ] }, { "cell_type": "code", "execution_count": 99, "id": "da8aea4f-89c1-4be6-a836-d63171007001", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0. , 1.57079633])" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.arcsin(np.array([0, 1]))" ] }, { "cell_type": "code", "execution_count": 100, "id": "0b60adb2-b671-4d00-be6e-5f25ae137745", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0. , 0.88137359])" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.arcsinh(np.array([0, 1]))" ] }, { "cell_type": "code", "execution_count": 101, "id": "acca0de4-f3c7-4e5f-9ba7-a0750c39dee4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 9])" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.where(a < 3, a , a * 3)" ] }, { "cell_type": "code", "execution_count": 102, "id": "86adf840-d172-4263-a74e-d90ea0970901", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([False, True, True])" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.logical_not(a<2) | ~(a<2)" ] }, { "cell_type": "code", "execution_count": 103, "id": "f797b40e-6960-427b-baa6-d2238e072958", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "array([2., 4.])" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.imag(np.array([1+2j, 3+4j]))" ] }, { "cell_type": "markdown", "id": "0d7b821c-87a3-4472-9384-84816c4030ee", "metadata": {}, "source": [ "## Binary Ufuncs: " ] }, { "cell_type": "code", "execution_count": 104, "id": "3b4d0c2a-333e-4211-9f71-95f5ccbd9bea", "metadata": {}, "outputs": [], "source": [ "a = np.array([1, 2, 3])\n", "b = np.array([4, 5, 6])" ] }, { "cell_type": "code", "execution_count": 105, "id": "0a38a790-86c5-439d-8d51-22dca84ab4be", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([5, 7, 9])" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.add(a, b) # a + b" ] }, { "cell_type": "code", "execution_count": 106, "id": "d1a21120-4eff-44fd-af5d-3a50f8b1fc4c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 4, 10, 18])" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = a.copy()\n", "c *= b\n", "c" ] }, { "cell_type": "code", "execution_count": 107, "id": "ce1862dd-4611-401c-b55c-d6ad68e41cf2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 0, 0])" ] }, "execution_count": 107, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.floor_divide(a, b)" ] }, { "cell_type": "code", "execution_count": 108, "id": "3f03d7e3-bb50-404d-8ddf-9ea67d01ed7a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1, 0])" ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.remainder(b, a)" ] }, { "cell_type": "code", "execution_count": 109, "id": "ab48fcb6-cbb4-44e3-94cc-505f70c2b879", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([4, 2, 2]), array([0, 1, 0]))" ] }, "execution_count": 109, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.divmod(b, a)" ] }, { "cell_type": "code", "execution_count": 110, "id": "709fde5a-d431-48cf-b365-642fede92e10", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1, 32, 729])" ] }, "execution_count": 110, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.power(a, b) # a ** b" ] }, { "cell_type": "code", "execution_count": 111, "id": "d62fb020-c8a4-43a9-a71f-c368437030d4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([4, 5, 6])" ] }, "execution_count": 111, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.maximum(a, b)" ] }, { "cell_type": "code", "execution_count": 112, "id": "4b543d5d-476e-45bf-88f1-50ff904ef9e6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-1., -2., -3.])" ] }, "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.copysign(a, -1)" ] }, { "cell_type": "code", "execution_count": 113, "id": "d172bc4d-c099-47bb-95ee-47f7fed90540", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ True, True, True])" ] }, "execution_count": 113, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.greater(b, a)" ] }, { "cell_type": "markdown", "id": "95556fe8-eec1-4ea6-8b70-097d32e969fc", "metadata": {}, "source": [ "## Broadcasting (binary operations with arrays of dissimilar dimension):" ] }, { "cell_type": "code", "execution_count": 114, "id": "e08c2b6d-1f8c-4c84-a7cd-45553360ce22", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([2, 4, 6])" ] }, "execution_count": 114, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array([1, 2, 3]) * 2 # => [1, 2, 3] * [2] => [1, 2, 3] * [2, 2, 2]" ] }, { "cell_type": "code", "execution_count": 115, "id": "966f6037-dd7e-433f-8b91-96133f0571fd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 2, 4, 6],\n", " [ 8, 10, 12]])" ] }, "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array([[1, 2, 3], # => [1, 2, 3] => [1, 2, 3] [2, 2, 2]\n", " [4, 5 ,6]]) * 2 # [4, 5, 6] * [2] [4, 5, 6] * [2, 2, 2]" ] }, { "cell_type": "code", "execution_count": 116, "id": "0866958c-f363-46f5-a6c4-2d159769ed08", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 2., 4., 6.],\n", " [12., 15., 18.]])" ] }, "execution_count": 116, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.multiply(np.array([[1, 2, 3], [4, 5, 6]]), # => [1, 2, 3] [2., 2., 2.]\n", " np.array([[2.], [3.]]) ) # [4, 5, 6] * [3., 3., 3.]" ] }, { "cell_type": "markdown", "id": "9c38765d-3f26-4322-8384-74955194a8df", "metadata": {}, "source": [ "## More logic operations:" ] }, { "cell_type": "code", "execution_count": 117, "id": "f7d32046-3925-4ade-b160-e37e89090f9a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.array([[1, 2], [3, 4]])\n", "np.array_equal([1,1],[1])" ] }, { "cell_type": "code", "execution_count": 118, "id": "96dee3f5-49cd-4ff7-8fef-b9b70c984e17", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 118, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.array_equiv([1,1],[1]) " ] }, { "cell_type": "code", "execution_count": 119, "id": "bbff703e-7b5a-43ad-ac58-43c54553ee61", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[99, 4],\n", " [ 6, 8]])" ] }, "execution_count": 119, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.select([a>1], [a*2], 99) " ] }, { "cell_type": "markdown", "id": "b3385b7a-d564-4af9-9a5f-2b320eb1ffb5", "metadata": {}, "source": [ "## Statistical operations:" ] }, { "cell_type": "code", "execution_count": 120, "id": "69fc89a2-5976-4817-8ace-22014f26a4bb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.5" ] }, "execution_count": 120, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.array([[1, 2], [3, 4]])\n", "np.mean(a)" ] }, { "cell_type": "code", "execution_count": 121, "id": "a7599c87-2e02-43a9-8f2b-f8c2d07b9634", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1.5, 3.5])" ] }, "execution_count": 121, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.mean(a, axis=1)" ] }, { "cell_type": "markdown", "id": "42db1339-6d89-4c28-b298-5f67bb810dad", "metadata": {}, "source": [ "# Array Transformation\n", "___ " ] }, { "cell_type": "code", "execution_count": 122, "id": "7f53965d-e872-4c51-aa42-94b661d76cf3", "metadata": {}, "outputs": [], "source": [ "a = np.array([[1, 2, 3], [4, 5, 6]])" ] }, { "cell_type": "code", "execution_count": 123, "id": "63239222-4851-4adc-b232-e4fc62703ca2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 4],\n", " [2, 5],\n", " [3, 6]])" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.transpose(a)" ] }, { "cell_type": "code", "execution_count": 124, "id": "eca6a4d6-04d7-44ea-bee7-37423cb8dd7b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2],\n", " [3, 4],\n", " [5, 6]])" ] }, "execution_count": 124, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.reshape(a, (3,2))" ] }, { "cell_type": "code", "execution_count": 125, "id": "f68d31d8-0b6f-4d70-9176-6385f1dd593e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 4, 2, 5, 3, 6])" ] }, "execution_count": 125, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.ravel(a, order='F')" ] }, { "cell_type": "code", "execution_count": 126, "id": "024c9d7a-67f4-4546-9ee0-9641ec94e6f4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[6, 5, 4],\n", " [3, 2, 1]])" ] }, "execution_count": 126, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.flip(a)" ] }, { "cell_type": "code", "execution_count": 127, "id": "96bab9e5-930b-4b28-882a-bf99b4ca4408", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[4, 5, 6],\n", " [1, 2, 3]])" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.flip(a, 0)" ] }, { "cell_type": "markdown", "id": "61687ce7-329e-4d34-919b-649cc3ead71b", "metadata": {}, "source": [ "## Combining & splitting:" ] }, { "cell_type": "code", "execution_count": 128, "id": "6652721d-cad5-4988-b5f2-17ddb069352f", "metadata": {}, "outputs": [], "source": [ "a = np.array([[1, 2, 3], [4, 5, 6]])\n", "b = np.array([[7, 8, 9]])" ] }, { "cell_type": "code", "execution_count": 129, "id": "cc04d75e-bc75-4715-a33f-00fba53115e0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3],\n", " [4, 5, 6],\n", " [7, 8, 9]])" ] }, "execution_count": 129, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.concatenate((a, b))" ] }, { "cell_type": "code", "execution_count": 130, "id": "d1ae99a1-3a27-43a2-a8c5-8e0b46c34657", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[array([1, 2, 3]), array([4, 5, 6])]" ] }, "execution_count": 130, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = np.ravel(a)\n", "np.split(c, 2)" ] }, { "cell_type": "code", "execution_count": 131, "id": "b946e88d-1f95-4408-8d21-77c5206e0c0e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[array([1, 2, 3]), array([4, 5, 6])]" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = np.ravel(a)\n", "np.split(c, 2)" ] }, { "cell_type": "code", "execution_count": 132, "id": "3c258a8b-e0af-429d-bde5-587865413432", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3, 4, 5, 6, 7, 8, 9])" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.concatenate((a, b), axis=None)" ] }, { "cell_type": "code", "execution_count": 133, "id": "8443827f-926c-4547-b7d8-f9b74949ee88", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3],\n", " [7, 8, 9]])" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d = np.array(\n", " [7,8,9])\n", "np.stack((a[0],d))" ] }, { "cell_type": "code", "execution_count": 134, "id": "9ca1dbd0-fc1f-4527-afa5-119da1a26f55", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[4, 5, 6],\n", " [7, 8, 9]])" ] }, "execution_count": 134, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.stack((a[1], d))" ] }, { "cell_type": "markdown", "id": "1eeb98d4-e83c-4690-83b9-a54defe6597e", "metadata": {}, "source": [ "# Sorting & searching:\n", "___ " ] }, { "cell_type": "code", "execution_count": 135, "id": "6032a351-d8de-470c-bcd2-510ac60d027f", "metadata": {}, "outputs": [], "source": [ "a = np.array([[4, 2, 1], [3, 6, 5]])" ] }, { "cell_type": "code", "execution_count": 136, "id": "37202d16-1259-4910-8e22-3e56a48794b9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 4],\n", " [3, 5, 6]])" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sort(a)" ] }, { "cell_type": "code", "execution_count": 137, "id": "7e16e2d8-d1de-4b92-817c-a816eb5f82ef", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[2, 1, 0],\n", " [0, 2, 1]])" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.argsort(a)" ] }, { "cell_type": "code", "execution_count": 138, "id": "9a2da8b9-a7b3-4a5f-9ec4-c1dd7e7e5c76", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3, 4, 5, 6])" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sort(a, axis=None)" ] }, { "cell_type": "code", "execution_count": 139, "id": "1198e1eb-8594-420b-beaf-329f40feb0d5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[3, 2, 1],\n", " [4, 6, 5]])" ] }, "execution_count": 139, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sort(a, axis=0)" ] }, { "cell_type": "code", "execution_count": 140, "id": "363de336-35f4-44cd-8993-5b865740f283", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1])" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.argmax(a,axis=1)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }