{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d0c20d6e-a68b-4022-85c5-501ba24a01ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "123\n" ] } ], "source": [ "print(123)" ] }, { "cell_type": "code", "execution_count": 2, "id": "91ef11b2-a866-4084-9f9c-9433a12ba191", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100\n" ] } ], "source": [ "print(100)" ] }, { "cell_type": "code", "execution_count": 6, "id": "6c0f0083", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[1 4 7]\n", " [2 5 8]\n", " [3 6 9]]\n", "Transposed Array:\n", " [[1 4 7]\n", " [2 5 8]\n", " [3 6 9]]\n", "Array Shape: (3, 3)\n", "Array Data Type: int64\n", "Array Element Size: 8\n", "Array Total Size: 72\n", "Element at 1st Row 2nd Column: 2\n", "Elements from 1st and 2nd Row, and 1st and 2nd Column:\n", " [[1 2]\n", " [4 5]]\n", "Sum of Array Elements: 45\n", "Average of Array Elements: 5.0\n", "Maximum Element in Array: 9\n", "Minimum Element in Array: 1\n" ] } ], "source": [ "import numpy as np\n", "\n", "# 生成一个 3x3 的二维数组\n", "arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n", "\n", "# 转置数组\n", "transposed_arr = arr.T\n", "print(transposed_arr)\n", "import numpy as np\n", "\n", "# 生成一个 3x3 的二维数组\n", "arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n", "\n", "# 转置数组\n", "transposed_arr = arr.T\n", "print(\"Transposed Array:\\n\", transposed_arr)\n", "\n", "# 数组的形状\n", "print(\"Array Shape:\", arr.shape)\n", "\n", "# 数组的类型\n", "print(\"Array Data Type:\", arr.dtype)\n", "\n", "# 数组元素的字节大小\n", "print(\"Array Element Size:\", arr.itemsize)\n", "\n", "# 数组元素的总字节大小\n", "print(\"Array Total Size:\", arr.nbytes)\n", "\n", "# 访问数组的某个元素\n", "print(\"Element at 1st Row 2nd Column:\", arr[0][1])\n", "\n", "# 访问数组的某个区域\n", "print(\"Elements from 1st and 2nd Row, and 1st and 2nd Column:\\n\", arr[:2, :2])\n", "\n", "# 对数组求和、平均值、最大值、最小值\n", "print(\"Sum of Array Elements:\", arr.sum())\n", "print(\"Average of Array Elements:\", arr.mean())\n", "print(\"Maximum Element in Array:\", arr.max())\n", "print(\"Minimum Element in Array:\", arr.min())\n" ] }, { "cell_type": "code", "execution_count": null, "id": "27161d42", "metadata": {}, "outputs": [], "source": [ "function bubbleSort(arr) {\n", " var len = arr.length;\n", " for (var i = 0; i < len - 1; i++) {\n", " for (var j = 0; j < len - 1 - i; j++) {\n", " if (arr[j] > arr[j + 1]) {\n", " var temp = arr[j + 1];\n", " arr[j + 1] = arr[j];\n", " arr[j] = temp;\n", " }\n", " }\n", " }\n", " return arr;\n", "}\n", "\n", "document.getElementById(\"myBtn\").addEventListener(\"click\", function() {\n", " var arr = [64, 34, 25, 12, 22, 11, 90];\n", " console.log(\"排序前的数组: \" + arr);\n", " bubbleSort(arr);\n", " console.log(\"排序后的数组: \" + arr);\n", "});\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.10 (default, Mar 13 2023, 10:26:41) \n[GCC 9.4.0]" }, "vscode": { "interpreter": { "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" } } }, "nbformat": 4, "nbformat_minor": 5 }