{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e362fc3f-d850-4454-9cc6-3a1f67c8003e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7251bbc-449e-4d3c-902a-f8f9adb635e8",
   "metadata": {},
   "source": [
    "## 1. Создайте массив `arr_1` размером 3х4, все элементы которого равны 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "69493d8a-70d3-4af3-86a8-a84ce93b7afd",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_1 = np.full((3, 4), 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "bd4217b2-bc3d-4041-9012-38b6b4b3e34a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 3, 3, 3],\n",
       "       [3, 3, 3, 3],\n",
       "       [3, 3, 3, 3]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd78badf-b6cf-4ed3-ae0d-b1d0c9cc03df",
   "metadata": {},
   "source": [
    "## 2. Создайте массив `arr_2`, заполненный случайными целыми числами от 0 до 9, размером 2х4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9a1f3f0d-9e05-41ac-8e42-5c41c286bf3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_2 = np.random.randint(0, 10, (2, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "20413389-5ab6-4886-ada2-8f4c9962c173",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[8, 1, 6, 2],\n",
       "       [5, 6, 0, 5]], dtype=int32)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "891bbf6f-d59b-4eb5-97cf-282b4baa87f4",
   "metadata": {},
   "source": [
    "## 3. Выведите на экран количество элементов в созданных массивах `arr_1` и `arr_2`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "85a8a59d-f389-49e7-bde3-dc6debc73c3b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_1.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b5103dd4-d631-4b39-9a95-f72166a98a5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_2.size"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "affd19f2-a863-46ff-b892-39b0851cf3f6",
   "metadata": {},
   "source": [
    "## 4. Соедините массивы `arr_1` и `arr_2` по нулевой оси"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8807a875-4869-4922-8e26-00f907b2f65a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 3, 3, 3],\n",
       "       [3, 3, 3, 3],\n",
       "       [3, 3, 3, 3],\n",
       "       [8, 1, 6, 2],\n",
       "       [5, 6, 0, 5]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack((arr_1, arr_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dedddf00-a3fb-47ec-ab76-5c80bfda90e2",
   "metadata": {},
   "source": [
    "## 5. Создайте массив `arr_3` из кортежа чисел `(1, 8, 6, 5, 8, 3)` с помощью функции `np.array()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ca8cdc99-85b4-4734-9705-7a8bc71da1d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_3 = np.array((1, 8, 6, 5, 8, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "82be3178-0707-4dc2-989a-bf333a26e826",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 8, 6, 5, 8, 3])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6020d268-a5b5-46d7-acb6-29b289df587e",
   "metadata": {},
   "source": [
    "## 6. Умножьте каждый элемент массива `arr_3` на число 3 и прибавьте к каждому элементу 1. Результат записишите в новый массив `arr_4`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5ca5b13c-4225-47d8-9cbd-54b8b6ed636c",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_4 = arr_3 * 3 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4df5abf7-2178-4fab-95b2-59feb2d36057",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 4, 25, 19, 16, 25, 10])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8497cd05-1b9d-436a-91fa-cb1964274f0d",
   "metadata": {},
   "source": [
    "## 7. Преобразуйте массив `arr_3` к двумерному массиву 2х3. Результат запишите в массив `arr_5`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7983ac22-3059-4610-8309-0d61b2021673",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_5 = arr_3.reshape(2, 3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0ec669da-e4bb-44f4-8869-66bdabf89464",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 8, 6],\n",
       "       [5, 8, 3]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_5"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7dbde90-11f9-427f-b0d2-c3ad86e1a2de",
   "metadata": {},
   "source": [
    "## 8. Определите минимальные элементы массива `arr_5` вдоль первой оси"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "92c33687-6b44-4f44-807b-6651db9c25d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 3])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.min(arr_5, axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad8dcce4-bd96-4275-9433-4534afa97140",
   "metadata": {},
   "source": [
    "## 9. Вычислите среднее арифметическое всех элементов массива `arr_5`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "d5a27373-e99d-48d6-8dcf-f39ac6f97358",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(5.166666666666667)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(arr_5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e4e0d351-29e2-4461-bbcd-ce78dbddd204",
   "metadata": {},
   "source": [
    "## 10. Создайте массив `arr_6`, состоящий из квадратов чисел от 0 до 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8727e571-cded-4a47-bf35-2da7bfaaef21",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_6 = np.arange(0, 11)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "45b52b38-d162-4351-a47f-440964b5a736",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0,   1,   4,   9,  16,  25,  36,  49,  64,  81, 100])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_6"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "950aa0ae-6f48-48dc-af69-0849cc728ae1",
   "metadata": {},
   "source": [
    "## 11. Выведите каждый второй элемент массива `arr_6`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2dab6d77-043f-4a63-a1ba-bb247feb9e65",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0,   4,  16,  36,  64, 100])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_6[::2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1877b231-c034-4edb-a4cb-444291dbc5c8",
   "metadata": {},
   "source": [
    "## 12. Выведите элементы массива `arr_6` в обратном порядке"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f02b737d-ca99-486d-b19e-1379de20a886",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([100,  81,  64,  49,  36,  25,  16,   9,   4,   1,   0])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_6[::-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09f50732-8bd8-4446-a7f9-7ce433bbd772",
   "metadata": {},
   "source": [
    "## 13. Каждому второму элементу массива `arr_6` присвойте значение 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d4aeab44-c8f6-46e8-b92b-ff6687e2b657",
   "metadata": {},
   "outputs": [],
   "source": [
    "arr_6[::2] = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "dc067e82-e514-43e1-a00b-ba3bf8e42394",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2,  1,  2,  9,  2, 25,  2, 49,  2, 81,  2])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr_6"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a720f9cd-1f7c-48d6-82c2-2e20943ac0b0",
   "metadata": {},
   "source": [
    "## 14. Проверьте, есть ли в массиве `arr_6` значение 49"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "875e0c7b-f732-4c05-befa-b78d6721df72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.True_"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.any(arr_6 == 49)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac92170f-0047-4c8d-91b9-4fd1f5f11828",
   "metadata": {},
   "source": [
    "## 15. Создайте двумерный массив `A`, состоящий из положительных и отрицательных чисел. Из массива `A` выберите все отрицательные элементы и запишите их в одномерный массив `B`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "aa795b2f-238f-422f-a7a9-0a1e4a5b2506",
   "metadata": {},
   "outputs": [],
   "source": [
    "A = np.random.randint(-9, 10, size = (3, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "cff86c7e-9922-4784-851b-d1872932b920",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 5,  9, -5],\n",
       "       [-4,  3,  1],\n",
       "       [ 1, -4, -9]], dtype=int32)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "88d5a577-c01a-4e4d-ae37-e28913d4d143",
   "metadata": {},
   "outputs": [],
   "source": [
    "B = A[A < 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "2e65ced2-825e-4bcd-b195-d09a99b12aee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-5, -4, -4, -9], dtype=int32)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B"
   ]
  }
 ],
 "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.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
