From 93d53c1d042042a956949f0975322b821d31be40 Mon Sep 17 00:00:00 2001 From: G61G612281337 Date: Sat, 5 Mar 2022 05:18:31 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=B7=20numpy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Котов Илья --- Numpy (26.02)/np (1).ipynb | 566 +++++++++++++++++++++++++++++++++++++ 1 file changed, 566 insertions(+) create mode 100644 Numpy (26.02)/np (1).ipynb diff --git a/Numpy (26.02)/np (1).ipynb b/Numpy (26.02)/np (1).ipynb new file mode 100644 index 0000000..d53c6de --- /dev/null +++ b/Numpy (26.02)/np (1).ipynb @@ -0,0 +1,566 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "np.ipynb", + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "id": "0lE0wE0kzhDR" + }, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "source": [ + "python_list = [1, 12, 13, 45, 76, 45, 98, 0]\n", + "print(type(python_list))\n", + "python_list = np.array(python_list) \n", + "print(type(python_list))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "62MmNGKDzmpr", + "outputId": "ac3e51e9-3207-42db-f0e0-a4e611036da5" + }, + "execution_count": 59, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "z = np.full(10, 1.5)\n", + "print(z)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "mADAWYqMzmv6", + "outputId": "5904f3c5-6f89-4abd-81a2-6a2b44762024" + }, + "execution_count": 60, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "z = np.zeros((5, 5))\n", + "print(z)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "VPhOI7iWzm19", + "outputId": "d2b29f3f-ae4e-407c-ce2d-124a42074aa7" + }, + "execution_count": 61, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0.]]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "ones = np.ones(12)\n", + "print(ones)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "bcJSG5SEzm71", + "outputId": "65fb6852-164c-4ffe-8d25-f4abb8337e4c" + }, + "execution_count": 62, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "ones = np.reshape(ones, (3, 4))\n", + "ones.shape" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "TNsFtX3eznCG", + "outputId": "85e988b1-a9de-4757-b6fc-b5d373572f68" + }, + "execution_count": 63, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(3, 4)" + ] + }, + "metadata": {}, + "execution_count": 63 + } + ] + }, + { + "cell_type": "code", + "source": [ + "Z = np.reshape(np.array([item for item in range(1, 21)]), (4, 5))\n", + "print(Z)\n", + "Z[2, 3] = -99\n", + "print(Z)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "lmGHAGj-znIG", + "outputId": "ec5fb00f-e0e6-4afe-e92c-b21946fe2a03" + }, + "execution_count": 64, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[ 1 2 3 4 5]\n", + " [ 6 7 8 9 10]\n", + " [11 12 13 14 15]\n", + " [16 17 18 19 20]]\n", + "[[ 1 2 3 4 5]\n", + " [ 6 7 8 9 10]\n", + " [ 11 12 13 -99 15]\n", + " [ 16 17 18 19 20]]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "first = np.random.randint(-10, 10, 15)\n", + "print(first)\n", + "second = first[::-1]\n", + "print(second)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "_66zJs1A2bbd", + "outputId": "6312c4d4-d537-4470-ea10-7636fac51ad3" + }, + "execution_count": 27, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[-10 4 -10 -4 1 -1 3 6 -2 -2 -3 5 -7 9 2]\n", + "[ 2 9 -7 5 -3 -2 -2 6 3 -1 1 -4 -10 4 -10]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "first = np.random.randint(-15, 15, (5, 5))\n", + "print(first)\n", + "first = np.where(first < 0, first**2, first)\n", + "print(first)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "5W9mB6rIPWwU", + "outputId": "fb580fe0-b7cd-4a72-f70e-900e420edf9e" + }, + "execution_count": 65, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[-13 6 5 -14 -11]\n", + " [-15 -8 -11 9 9]\n", + " [-11 -9 -13 -11 11]\n", + " [ 0 12 6 13 -7]\n", + " [-12 7 -11 -14 1]]\n", + "[[169 6 5 196 121]\n", + " [225 64 121 9 9]\n", + " [121 81 169 121 11]\n", + " [ 0 12 6 13 49]\n", + " [144 7 121 196 1]]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "first = np.random.randint(-15, 15, 15).reshape(3, 5)\n", + "print(first)\n", + "print(np.max(first))\n", + "print(np.min(first))\n", + "print(first.mean(axis=1))\n", + "print(first.mean(axis=0))\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "TwI2cJKr3YLf", + "outputId": "2dcb90dc-8709-47b6-803f-213a0a6ac8fa" + }, + "execution_count": 66, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[ 8 8 3 -12 -1]\n", + " [-10 7 10 -12 -9]\n", + " [ 0 0 13 5 3]]\n", + "13\n", + "-12\n", + "[ 1.2 -2.8 4.2]\n", + "[-0.66666667 5. 8.66666667 -6.33333333 -2.33333333]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "a = np.random.randint(-10, 10, (2, 5))\n", + "first_axis = np.random.randint(4, 6)\n", + "b = np.random.randint(-10, 10, (first_axis, 3))\n", + "if a.shape[1] == b.shape[0]:\n", + " print(a @ b)\n", + "else:\n", + " print('err')" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "GCTwDNgS5SVN", + "outputId": "493087ef-187e-49f3-f6b7-496fa6c35098" + }, + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[ 88 87 -33]\n", + " [ 77 58 -32]]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "import matplotlib.pyplot as plt\n", + "\n", + "mask = np.random.uniform(2, -12, (5, 5)) \n", + "matrix = np.copy(mask)\n", + "for i in range(5):\n", + " for j in range(5):\n", + " if j < i:\n", + " matrix[i, j] = 0\n", + "\n", + "plt.imshow(matrix)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 282 + }, + "id": "2YeEY9nG-yYv", + "outputId": "fe98dec3-0da3-4847-f38d-0a1ba36f039b" + }, + "execution_count": 67, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": {}, + "execution_count": 67 + }, + { + "output_type": "display_data", + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD4CAYAAAA0L6C7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAb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BYogaKIaogWKIGiiGqIFiiBoo5r8QOQCSYwRmbgAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + } + } + ] + }, + { + "cell_type": "code", + "source": [ + "mask = np.reshape(np.random.normal(10, 2, 25), (5, 5))\n", + "matrix = np.copy(mask)\n", + "for i in range(5):\n", + " for j in range(5):\n", + " if j == i:\n", + " matrix[i, j] = 0\n", + "plt.imshow(matrix)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 282 + }, + "id": "ZUqBdEQjAAPc", + "outputId": "d57312b0-152b-4c03-e86e-3120a49613b7" + }, + "execution_count": 68, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "" + ] + }, + "metadata": {}, + "execution_count": 68 + }, + { + "output_type": "display_data", + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPUAAAD4CAYAAAA0L6C7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAJmklEQVR4nO3d72tdhR3H8c9nMbVOnZ0/ptJ01oETijCFUB0VBt2E+AMFHynogyH0weaoIDh96P4AkYEbdFocKIqgiIhDOqyI4NSoVaytW3HtWnF0ruus+Ks/PnuQ+6CTpjn39p57cr++XxDIzQ3nfgh55yQ34cRJBKCOb3U9AMBwETVQDFEDxRA1UAxRA8Wc1MZBl/jkLNWpbRx66L51cSsfgtYcibue0JczJj/vekJj35v4susJje3afUgf7zt8zE+GVj6jl+pUXe6ftnHooTvlD+d2PaEvXxwery9CM+du7XpCY79a9kHXExq7YmbPvPfx7TdQDFEDxRA1UAxRA8UQNVAMUQPFEDVQDFEDxRA1UAxRA8UQNVAMUQPFEDVQDFEDxRA1UAxRA8UQNVBMo6htz9h+3/YO23e3PQrA4BaM2vaEpAckXS1pl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u+s9x2N7o+29tt/testCbK+wvdn2e7a32l7f9ab52F5q+zXbb/e23tv1piZsT9h+y/azo3rMRR+17QlJD0i6WtIqSTfbXtXtquN6WNJM1yMaOiTpziSrJF0h6ZeL+GP7paS1SX4k6VJJM7av6HhTE+slbRvlAy76qCWtlrQjyQdJvtLcf968oeNN80rykqR9Xe9oIslHSd7svX5Ac598y7tddWyZ82nv5mTvZVE/y2t7StK1kh4c5eOOQ9TLJe0+6vYeLdJPvHFme6WkyyS92u2S+fW+ld0iaa+kTUkW7dae+yXdJenIKB90HKJGy2yfJulJSXck+aTrPfNJcjjJpZKmJK22fUnXm+Zj+zpJe5O8MerHHoeoP5S04qjbU723YQhsT2ou6EeTPNX1niaS7Je0WYv7uYs1kq63vVNzPzKutf3IKB54HKJ+XdJFti+0vURz//j+mY43lWDbkh6StC3JfV3vOR7b59he1nv9FElXSdre7ar5JbknyVSSlZr7nH0hyS2jeOxFH3WSQ5Jul/S85p7IeSLJ1m5Xzc/2Y5JekXSx7T22b+t603GskXSr5s4iW3ov13Q9ah7nS9ps+x3NfaHflGRkvyYaJ/yZKFDMoj9TA+gPUQPFEDVQDFEDxRA1UAxRA8UQNVDM/wDRnwcuJkGYiQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + } + } + ] + }, + { + "cell_type": "code", + "source": [ + "a = np.random.randint(0,2,5)\n", + "print(a)\n", + "b = np.random.randint(0,2,5)\n", + "print(b)\n", + "equal = sum(a == b) == len(a)\n", + "equal" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "X9e4Zx2tDEPd", + "outputId": "6b497385-bff1-4d98-b89d-d5415679370e" + }, + "execution_count": 69, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1 0 1 0 1]\n", + "[0 1 1 0 1]\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "False" + ] + }, + "metadata": {}, + "execution_count": 69 + } + ] + }, + { + "cell_type": "code", + "source": [ + "import random\n", + "import math\n", + "r, c = random.randint(3, 7), random.randint(2, 12)\n", + "a = np.random.randint(-10, 10, (r, c))\n", + "print(a)\n", + "N = random.randint(1, math.floor(r * c / 2))\n", + "print(N)\n", + "sample = np.random.choice(a.flatten(), N)\n", + "print(sample)" + ], + "metadata": { + "id": "MwzciLI5EO64" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "a = np.array([1, np.NaN, np.Inf, np.NaN], float)\n", + "for i in range(a.shape[0]):\n", + " if np.isnan(a)[i] == True or np.isinf(a)[i] == True:\n", + " a[i] = 0\n", + "a" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "0bLYOVi25uiU", + "outputId": "d951af68-5e6b-40a6-ffae-0e1a72426b6b" + }, + "execution_count": 17, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "array([1., 0., 3., 0., 0.])" + ] + }, + "metadata": {}, + "execution_count": 17 + } + ] + }, + { + "cell_type": "code", + "source": [ + "axis = random.randint(1, 32) #maximum supported dimension for an ndarray is 32, found 48\n", + "print(axis)\n", + "matrix = np.zeros(tuple(np.ones((axis), dtype=int)))\n", + "print(len(matrix.shape))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "kLld6pdJ6dhK", + "outputId": "ab670105-9dbe-45e4-a25f-5c04358ad13a" + }, + "execution_count": 37, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "26\n", + "26\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "matrix = np.random.normal(50, 10, (10,3))\n", + "print(matrix)\n", + "indexes = ([list(item).index(min(item)) for item in matrix])\n", + "print(indexes)\n", + "print(matrix.min(axis=1))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "eL9YszZK-FxE", + "outputId": "a0f481ef-9cb3-4737-ecfe-eb0114203a67" + }, + "execution_count": 72, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[[39.72295187 48.23046171 58.82426042]\n", + " [46.20571315 72.60337282 44.51288964]\n", + " [49.86416395 58.44508971 56.41797436]\n", + " [50.87964422 48.52010877 49.65290726]\n", + " [67.75970867 53.75331565 48.07428749]\n", + " [42.80226668 43.5844297 53.65229794]\n", + " [39.74184621 39.5714073 73.87156043]\n", + " [41.20484651 51.38292113 51.86161091]\n", + " [29.30603924 56.11375085 44.34023531]\n", + " [42.9365361 43.77883603 42.53331532]]\n", + "[0, 2, 0, 1, 2, 0, 1, 0, 0, 2]\n", + "[39.72295187 44.51288964 49.86416395 48.52010877 48.07428749 42.80226668\n", + " 39.5714073 41.20484651 29.30603924 42.53331532]\n" + ] + } + ] + } + ] +} \ No newline at end of file