2zadanie/numpy.ipynb

120 lines
3.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a2f486bd-5b87-4e0f-9327-2ba680c00ebb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Сумма элементов массива: 15\n",
"Среднее значение: 3.0\n",
"Медиана: 3.0\n",
"Стандартное отклонение: 1.4142135623730951\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"arr = np.array([1, 2, 3, 4, 5])\n",
"print(\"Сумма элементов массива:\", np.sum(arr))\n",
"print(\"Среднее значение:\", np.mean(arr))\n",
"print(\"Медиана:\", np.median(arr))\n",
"print(\"Стандартное отклонение:\", np.std(arr))\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "896a8a44-ea62-4a5c-97ba-d1d4edc1d694",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Двумерный массив (матрица):\n",
"[[1 2]\n",
" [3 4]]\n"
]
}
],
"source": [
"matrix = np.array([[1, 2], [3, 4]])\n",
"print(\"Двумерный массив (матрица):\")\n",
"print(matrix)\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ce9bcbd6-a927-4e29-9206-32172f24299f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Массив через linspace: [ 0. 1.11111111 2.22222222 3.33333333 4.44444444 5.55555556\n",
" 6.66666667 7.77777778 8.88888889 10. ]\n",
"\n",
"Случайные числа:\n",
" [[-0.46721747 0.42148654]\n",
" [ 1.34381602 0.67923817]]\n",
"\n",
"Результат умножения векторов (dot): 11\n"
]
}
],
"source": [
"# 1. Создаем 10 чисел от 0 до 10 с равным шагом\n",
"line = np.linspace(0, 10, 10)\n",
"print(\"Массив через linspace:\", line)\n",
"\n",
"# 2. Генерируем случайные числа (матрица 2x2)\n",
"rand_arr = np.random.randn(2, 2)\n",
"print(\"\\nСлучайные числа:\\n\", rand_arr)\n",
"\n",
"# 3. Скалярное произведение векторов (np.dot)\n",
"v1 = np.array([1, 2])\n",
"v2 = np.array([3, 4])\n",
"result = np.dot(v1, v2) # 1*3 + 2*4 = 11\n",
"print(\"\\nРезультат умножения векторов (dot):\", result)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1759f664-5a9e-46fc-9e16-1c7f935f465e",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}