From b9200ba6ea8e66e4b93adcd7c1fcdefc0f74dae6 Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Fri, 5 Dec 2025 20:12:45 +0800 Subject: [PATCH 01/12] =?UTF-8?q?ops=E5=8F=98=E6=9B=B4=E4=B8=BAmint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/0_ndarray.ipynb | 135 +++++++++++------------ 1 file changed, 66 insertions(+), 69 deletions(-) diff --git a/chapter_02_preliminaries/0_ndarray.ipynb b/chapter_02_preliminaries/0_ndarray.ipynb index a89de95..9914b91 100644 --- a/chapter_02_preliminaries/0_ndarray.ipynb +++ b/chapter_02_preliminaries/0_ndarray.ipynb @@ -9,12 +9,12 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "import mindspore as ms\n", - "import mindspore.ops as ops" + "from mindspore import mint" ] }, { @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -35,13 +35,13 @@ "Tensor(shape=[12], dtype=Int64, value= [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])" ] }, - "execution_count": 2, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "x = ops.arange(12)\n", + "x = mint.arange(12)\n", "x" ] }, @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -63,7 +63,7 @@ "(12,)" ] }, - "execution_count": 3, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -74,7 +74,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -83,7 +83,7 @@ "12" ] }, - "execution_count": 4, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -106,7 +106,7 @@ " [ 8, 9, 10, 11]])" ] }, - "execution_count": 5, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -118,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -133,18 +133,18 @@ " [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]]])" ] }, - "execution_count": 6, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ops.zeros((2, 3, 4))" + "mint.zeros((2, 3, 4))" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -159,41 +159,41 @@ " [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]])" ] }, - "execution_count": 7, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ops.ones((2, 3, 4))" + "mint.ones((2, 3, 4))" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Tensor(shape=[3, 4], dtype=Float32, value=\n", - "[[ 1.13799882e+00, -4.56003368e-01, -8.73978078e-01, 9.31848228e-01],\n", - " [ 1.23433046e-01, 1.21131825e+00, 1.28748190e+00, 2.70856231e-01],\n", - " [ 7.04268515e-01, -1.69450343e+00, -9.84726071e-01, -1.32821691e+00]])" + "[[-9.32621598e-01, -1.32283643e-01, 6.06187470e-02, 3.02344084e-01],\n", + " [-3.13425899e-01, -1.18156695e+00, -1.46659148e+00, -1.17737758e+00],\n", + " [-1.85464215e+00, -4.99636263e-01, 1.80253182e-02, -1.73694491e-01]])" ] }, - "execution_count": 8, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ops.randn(3, 4)" + "mint.randn(3, 4)" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -205,7 +205,7 @@ " [4, 3, 2, 1]])" ] }, - "execution_count": 9, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -216,7 +216,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -229,7 +229,7 @@ " Tensor(shape=[4], dtype=Float32, value= [ 1.00000000e+00, 4.00000000e+00, 1.60000000e+01, 6.40000000e+01]))" ] }, - "execution_count": 10, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } @@ -242,27 +242,27 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "Tensor(shape=[4], dtype=Float32, value= [ 2.71828198e+00, 7.38905573e+00, 5.45981445e+01, 2.98095825e+03])" + "Tensor(shape=[4], dtype=Float32, value= [ 2.71828175e+00, 7.38905621e+00, 5.45981483e+01, 2.98095801e+03])" ] }, - "execution_count": 11, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ops.exp(x)" + "mint.exp(x)" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -281,20 +281,20 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01 ... 3.00000000e+00, 2.00000000e+00, 1.00000000e+00]]))" ] }, - "execution_count": 13, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "X = ops.arange(12, dtype=ms.float32).reshape((3,4))\n", + "X = mint.arange(12, dtype=ms.float32).reshape((3,4))\n", "Y = ms.Tensor([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])\n", - "ops.cat((X, Y), axis=0), ops.cat((X, Y), axis=1)" + "mint.cat((X, Y), dim=0), mint.cat((X, Y), dim=1)" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -306,7 +306,7 @@ " [False, False, False, False]])" ] }, - "execution_count": 14, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -317,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -326,7 +326,7 @@ "Tensor(shape=[], dtype=Float32, value= 66)" ] }, - "execution_count": 15, + "execution_count": 45, "metadata": {}, "output_type": "execute_result" } @@ -337,7 +337,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -351,20 +351,20 @@ " [[0, 1]]))" ] }, - "execution_count": 16, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "a = ops.arange(3).reshape((3, 1))\n", - "b = ops.arange(2).reshape((1, 2))\n", + "a = mint.arange(3).reshape((3, 1))\n", + "b = mint.arange(2).reshape((1, 2))\n", "a, b" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -376,7 +376,7 @@ " [2, 3]])" ] }, - "execution_count": 17, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -387,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -399,7 +399,7 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01, 1.10000000e+01]]))" ] }, - "execution_count": 18, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } @@ -410,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -422,7 +422,7 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01, 1.10000000e+01]])" ] }, - "execution_count": 19, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -434,7 +434,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -446,7 +446,7 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01, 1.10000000e+01]])" ] }, - "execution_count": 20, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -458,7 +458,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 51, "metadata": {}, "outputs": [ { @@ -467,7 +467,7 @@ "False" ] }, - "execution_count": 21, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -487,15 +487,15 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 52, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "id(Z): 140072895924000\n", - "id(Z): 140072895924000\n" + "id(Z): 281471574030608\n", + "id(Z): 281471574030608\n" ] } ], @@ -515,7 +515,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 53, "metadata": {}, "outputs": [ { @@ -524,7 +524,7 @@ "True" ] }, - "execution_count": 25, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -544,7 +544,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 54, "metadata": {}, "outputs": [ { @@ -553,7 +553,7 @@ "(numpy.ndarray, mindspore.common.tensor.Tensor)" ] }, - "execution_count": 26, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -566,19 +566,16 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(Tensor(shape=[1], dtype=Float32, value= [ 3.50000000e+00]),\n", - " Tensor(shape=[], dtype=Float32, value= 3.5),\n", - " 3.5,\n", - " 3)" + "(Tensor(shape=[1], dtype=Float32, value= [ 3.50000000e+00]), 3.5, 3.5, 3)" ] }, - "execution_count": 27, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -592,9 +589,9 @@ ], "metadata": { "kernelspec": { - "display_name": "mindspore2.0", + "display_name": "Python 3.10", "language": "python", - "name": "mindspore2.0" + "name": "py310" }, "language_info": { "codemirror_mode": { @@ -606,7 +603,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.15" + "version": "3.10.14" } }, "nbformat": 4, From 3de2f8b6f377acdfd9b90d8b81723db5cb3d5ce1 Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Fri, 5 Dec 2025 20:15:34 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E9=80=82=E9=85=8Dmindspore2.7.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/1_pandas.ipynb | 62 +++++++++++-------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/chapter_02_preliminaries/1_pandas.ipynb b/chapter_02_preliminaries/1_pandas.ipynb index 42d3301..0a29ace 100644 --- a/chapter_02_preliminaries/1_pandas.ipynb +++ b/chapter_02_preliminaries/1_pandas.ipynb @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -66,25 +66,17 @@ "2 4.0 NaN\n", "3 3.0 NaN\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/tmp/ipykernel_31728/38268100.py:2: FutureWarning: The default value of numeric_only in DataFrame.mean is deprecated. In a future version, it will default to False. In addition, specifying 'numeric_only=None' is deprecated. Select only valid columns or specify the value of numeric_only to silence this warning.\n", - " inputs = inputs.fillna(inputs.mean())\n" - ] } ], "source": [ "inputs, outputs = data.iloc[:, 0:2], data.iloc[:, 2]\n", - "inputs = inputs.fillna(inputs.mean())\n", + "inputs = inputs.fillna(inputs.mean(numeric_only=True))\n", "print(inputs)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -92,10 +84,10 @@ "output_type": "stream", "text": [ " NumRooms Alley_Pave Alley_nan\n", - "0 3.0 1 0\n", - "1 2.0 0 1\n", - "2 4.0 0 1\n", - "3 3.0 0 1\n" + "0 3.0 True False\n", + "1 2.0 False True\n", + "2 4.0 False True\n", + "3 3.0 False True\n" ] } ], @@ -106,30 +98,30 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "(Tensor(shape=[4, 3], dtype=Float64, value=\n", - " [[ 3.00000000e+00, 1.00000000e+00, 0.00000000e+00],\n", - " [ 2.00000000e+00, 0.00000000e+00, 1.00000000e+00],\n", - " [ 4.00000000e+00, 0.00000000e+00, 1.00000000e+00],\n", - " [ 3.00000000e+00, 0.00000000e+00, 1.00000000e+00]]),\n", - " Tensor(shape=[4], dtype=Int64, value= [127500, 106000, 178100, 140000]))" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "X: [[3. 1. 0.]\n", + " [2. 0. 1.]\n", + " [4. 0. 1.]\n", + " [3. 0. 1.]]\n", + "y: [127500. 106000. 178100. 140000.]\n" + ] } ], "source": [ "import mindspore as ms\n", + "import numpy as np\n", + "\n", + "X = ms.Tensor(inputs.values.astype(np.float32), ms.float32)\n", + "y = ms.Tensor(outputs.values.astype(np.float32), ms.float32)\n", "\n", - "X, y = ms.Tensor(inputs.values), ms.Tensor(outputs.values)\n", - "X, y" + "print(\"X:\", X)\n", + "print(\"y:\", y)" ] }, { @@ -142,9 +134,9 @@ ], "metadata": { "kernelspec": { - "display_name": "mindspore2.0", + "display_name": "Python 3.10", "language": "python", - "name": "mindspore2.0" + "name": "py310" }, "language_info": { "codemirror_mode": { @@ -156,7 +148,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.15" + "version": "3.10.14" } }, "nbformat": 4, From c11cf20d8cf266e09c1de340e3770b4353ea7e28 Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Fri, 5 Dec 2025 20:16:47 +0800 Subject: [PATCH 03/12] =?UTF-8?q?ops=E5=8F=98=E6=9B=B4=E4=B8=BAmint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2_linear-algebra.ipynb | 167 +++++++++--------- 1 file changed, 85 insertions(+), 82 deletions(-) diff --git a/chapter_02_preliminaries/2_linear-algebra.ipynb b/chapter_02_preliminaries/2_linear-algebra.ipynb index 1fa7f94..91fbc6c 100644 --- a/chapter_02_preliminaries/2_linear-algebra.ipynb +++ b/chapter_02_preliminaries/2_linear-algebra.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -14,13 +14,14 @@ " Tensor(shape=[], dtype=Float32, value= 9))" ] }, - "execution_count": 1, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import mindspore\n", + "from mindspore import mint\n", "\n", "x = mindspore.Tensor(3.0)\n", "y = mindspore.Tensor(2.0)\n", @@ -30,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -39,22 +40,19 @@ "Tensor(shape=[4], dtype=Int64, value= [0, 1, 2, 3])" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# 这里需要用到mindspore的ops算子\n", - "import mindspore.ops as ops\n", - "\n", - "x = ops.arange(4)\n", + "x = mint.arange(4)\n", "x" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -63,7 +61,7 @@ "Tensor(shape=[], dtype=Int64, value= 3)" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -74,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -83,7 +81,7 @@ "4" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -94,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -103,7 +101,7 @@ "(4,)" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -134,7 +132,7 @@ } ], "source": [ - "A = ops.arange(20).reshape(5, 4)\n", + "A = mint.arange(20).reshape(5, 4)\n", "A" ] }, @@ -164,7 +162,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -176,7 +174,7 @@ " [3, 4, 5]])" ] }, - "execution_count": 11, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -188,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -200,7 +198,7 @@ " [ True, True, True]])" ] }, - "execution_count": 12, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -211,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -226,19 +224,19 @@ " [20, 21, 22, 23]]])" ] }, - "execution_count": 13, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "X = ops.arange(24).reshape(2, 3, 4)\n", + "X = mint.arange(24).reshape(2, 3, 4)\n", "X" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -258,20 +256,20 @@ " [ 3.20000000e+01, 3.40000000e+01, 3.60000000e+01, 3.80000000e+01]]))" ] }, - "execution_count": 14, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "A = ops.arange(20, dtype=mindspore.float32).reshape(5, 4)\n", + "A = mint.arange(20, dtype=mindspore.float32).reshape(5, 4)\n", "B = A.copy()\n", "A, A + B" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -285,7 +283,7 @@ " [ 2.56000000e+02, 2.89000000e+02, 3.24000000e+02, 3.61000000e+02]])" ] }, - "execution_count": 15, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -296,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -312,20 +310,20 @@ " (2, 3, 4))" ] }, - "execution_count": 16, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = 2\n", - "X = ops.arange(24).reshape(2, 3, 4)\n", + "X = mint.arange(24).reshape(2, 3, 4)\n", "a + X, (a * X).shape" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -335,19 +333,19 @@ " Tensor(shape=[], dtype=Float32, value= 6))" ] }, - "execution_count": 17, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "x = ops.arange(4, dtype=mindspore.float32)\n", + "x = mint.arange(4, dtype=mindspore.float32)\n", "x, x.sum()" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -356,7 +354,7 @@ "((5, 4), Tensor(shape=[], dtype=Float32, value= 190))" ] }, - "execution_count": 18, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -367,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -377,7 +375,7 @@ " (4,))" ] }, - "execution_count": 21, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -389,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -399,7 +397,7 @@ " (5,))" ] }, - "execution_count": 24, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -411,7 +409,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -420,7 +418,7 @@ "Tensor(shape=[], dtype=Float32, value= 190)" ] }, - "execution_count": 22, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -431,7 +429,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -441,7 +439,7 @@ " Tensor(shape=[], dtype=Float32, value= 9.5))" ] }, - "execution_count": 23, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -452,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -462,7 +460,7 @@ " Tensor(shape=[4], dtype=Float32, value= [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01, 1.10000000e+01]))" ] }, - "execution_count": 25, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -473,7 +471,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -487,7 +485,7 @@ " [ 7.00000000e+01]])" ] }, - "execution_count": 26, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -499,7 +497,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -507,13 +505,13 @@ "text/plain": [ "Tensor(shape=[5, 4], dtype=Float32, value=\n", "[[ 0.00000000e+00, 1.66666672e-01, 3.33333343e-01, 5.00000000e-01],\n", - " [ 1.81818187e-01, 2.27272734e-01, 2.72727281e-01, 3.18181813e-01],\n", - " [ 2.10526317e-01, 2.36842111e-01, 2.63157904e-01, 2.89473683e-01],\n", + " [ 1.81818187e-01, 2.27272719e-01, 2.72727281e-01, 3.18181813e-01],\n", + " [ 2.10526317e-01, 2.36842096e-01, 2.63157904e-01, 2.89473683e-01],\n", " [ 2.22222224e-01, 2.40740746e-01, 2.59259254e-01, 2.77777791e-01],\n", - " [ 2.28571430e-01, 2.42857143e-01, 2.57142872e-01, 2.71428585e-01]])" + " [ 2.28571430e-01, 2.42857143e-01, 2.57142842e-01, 2.71428555e-01]])" ] }, - "execution_count": 27, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -524,9 +522,16 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 25, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "." + ] + }, { "data": { "text/plain": [ @@ -538,7 +543,7 @@ " [ 4.00000000e+01, 4.50000000e+01, 5.00000000e+01, 5.50000000e+01]])" ] }, - "execution_count": 28, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -549,7 +554,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -560,21 +565,19 @@ " Tensor(shape=[], dtype=Float32, value= 6))" ] }, - "execution_count": 29, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "import mindspore.numpy as mnp\n", - "\n", - "y = ops.ones(4, dtype = mindspore.float32)\n", - "x, y, mnp.dot(x, y)" + "y = mint.ones(4, dtype=mindspore.float32)\n", + "x, y, mint.dot(x, y)" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -583,18 +586,18 @@ "Tensor(shape=[], dtype=Float32, value= 6)" ] }, - "execution_count": 30, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ops.sum(x * y)" + "mint.sum(x * y)" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -605,18 +608,18 @@ " Tensor(shape=[5], dtype=Float32, value= [ 1.40000000e+01, 3.80000000e+01, 6.20000000e+01, 8.60000000e+01, 1.10000000e+02]))" ] }, - "execution_count": 31, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "A.shape, x.shape, mnp.dot(A, x)" + "A.shape, x.shape, mint.matmul(A, x)" ] }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -630,19 +633,19 @@ " [ 7.00000000e+01, 7.00000000e+01, 7.00000000e+01]])" ] }, - "execution_count": 32, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "B = ops.ones((4, 3))\n", - "ops.matmul(A, B)" + "B = mint.ones((4, 3))\n", + "mint.matmul(A, B)" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -651,19 +654,19 @@ "Tensor(shape=[], dtype=Float32, value= 5)" ] }, - "execution_count": 34, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u = mindspore.Tensor([3.0, -4.0], dtype=mindspore.float32)\n", - "ops.norm(u, dim=0)" + "mint.norm(u, dim=0)" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -672,18 +675,18 @@ "Tensor(shape=[], dtype=Float32, value= 7)" ] }, - "execution_count": 35, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ops.abs(u).sum()" + "mint.abs(u).sum()" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -692,13 +695,13 @@ "Tensor(shape=[], dtype=Float32, value= 6)" ] }, - "execution_count": 40, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ops.norm(ops.ones((4, 9)), dim=(0, 1))" + "mint.norm(mint.ones((4, 9)), dim=(0, 1))" ] }, { @@ -711,9 +714,9 @@ ], "metadata": { "kernelspec": { - "display_name": "MindSpore", + "display_name": "Python 3.10", "language": "python", - "name": "mindspore" + "name": "py310" }, "language_info": { "codemirror_mode": { @@ -725,7 +728,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.10.14" } }, "nbformat": 4, From a8097a2128670d58e47db60338d90fcef8f85e1e Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Fri, 5 Dec 2025 20:17:49 +0800 Subject: [PATCH 04/12] =?UTF-8?q?ops=E5=8F=98=E6=9B=B4=E4=B8=BAmint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/4_autograd.ipynb | 68 +++++++++++------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/chapter_02_preliminaries/4_autograd.ipynb b/chapter_02_preliminaries/4_autograd.ipynb index 3ec2908..273fde2 100644 --- a/chapter_02_preliminaries/4_autograd.ipynb +++ b/chapter_02_preliminaries/4_autograd.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -11,7 +11,7 @@ "Tensor(shape=[4], dtype=Float32, value= [ 0.00000000e+00, 1.00000000e+00, 2.00000000e+00, 3.00000000e+00])" ] }, - "execution_count": 2, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -19,8 +19,9 @@ "source": [ "import mindspore as ms\n", "import mindspore.ops as ops\n", + "from mindspore import mint, grad\n", "\n", - "x = ops.arange(4.0)\n", + "x = mint.arange(4.0)\n", "x" ] }, @@ -46,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -55,17 +56,14 @@ "Tensor(shape=[], dtype=Float32, value= 28)" ] }, - "execution_count": 3, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "import mindspore.numpy as mnp\n", - "from mindspore import grad\n", - "\n", "def forward(x):\n", - " return 2 * mnp.dot(x, x)\n", + " return 2 * mint.dot(x, x)\n", "\n", "y = forward(x)\n", "y" @@ -80,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -89,7 +87,7 @@ "Tensor(shape=[4], dtype=Float32, value= [ 0.00000000e+00, 4.00000000e+00, 8.00000000e+00, 1.20000000e+01])" ] }, - "execution_count": 8, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -101,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -110,7 +108,7 @@ "Tensor(shape=[4], dtype=Bool, value= [ True, True, True, True])" ] }, - "execution_count": 9, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -128,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -137,14 +135,14 @@ "Tensor(shape=[4], dtype=Float32, value= [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00])" ] }, - "execution_count": 11, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def forward(x):\n", - " return x.sum()\n", + " return mint.sum(x)\n", "\n", "x_grad = grad(forward)(x)\n", "x_grad" @@ -152,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -161,7 +159,7 @@ "Tensor(shape=[4], dtype=Float32, value= [ 0.00000000e+00, 2.00000000e+00, 4.00000000e+00, 6.00000000e+00])" ] }, - "execution_count": 12, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -169,7 +167,7 @@ "source": [ "def forward(x):\n", " y = x * x\n", - " return y.sum()\n", + " return mint.sum(y)\n", "\n", "x_grad = grad(forward)(x)\n", "x_grad" @@ -177,7 +175,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -186,7 +184,7 @@ "Tensor(shape=[4], dtype=Bool, value= [ True, True, True, True])" ] }, - "execution_count": 13, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -205,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -214,7 +212,7 @@ "Tensor(shape=[4], dtype=Bool, value= [ True, True, True, True])" ] }, - "execution_count": 14, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -222,22 +220,24 @@ "source": [ "def forward(x):\n", " y = x * x\n", - " return y.sum()\n", + " return mint.sum(y)\n", + "\n", "x_grad = grad(forward)(x)\n", "x_grad == 2 * x" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def f(a):\n", " b = a * 2\n", - " while ops.norm(b, dim=0) < 1000:\n", + " while mint.norm(b, dim=0) < 1000:\n", " b = b * 2\n", - " if b.sum() > 0:\n", + " \n", + " if mint.sum(b) > 0:\n", " c = b\n", " else:\n", " c = 100 * b\n", @@ -246,18 +246,18 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "a = ops.randn(())\n", + "a = mint.randn(())\n", "d = f(a)\n", "a_grad = grad(f)(a)" ] }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -266,7 +266,7 @@ "Tensor(shape=[], dtype=Bool, value= True)" ] }, - "execution_count": 20, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -278,9 +278,9 @@ ], "metadata": { "kernelspec": { - "display_name": "mindspore2.0", + "display_name": "Python 3.10", "language": "python", - "name": "mindspore2.0" + "name": "py310" }, "language_info": { "codemirror_mode": { @@ -292,7 +292,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.15" + "version": "3.10.14" } }, "nbformat": 4, From b6d0755d52f62a8d39da760ff8d7e79eedf7f73e Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Fri, 5 Dec 2025 20:18:44 +0800 Subject: [PATCH 05/12] =?UTF-8?q?ops=E5=8F=98=E6=9B=B4=E4=B8=BAmint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/6_lookup-api.ipynb | 111 ++++++++++++++++---- 1 file changed, 89 insertions(+), 22 deletions(-) diff --git a/chapter_02_preliminaries/6_lookup-api.ipynb b/chapter_02_preliminaries/6_lookup-api.ipynb index 54d7489..e2bf2d7 100644 --- a/chapter_02_preliminaries/6_lookup-api.ipynb +++ b/chapter_02_preliminaries/6_lookup-api.ipynb @@ -2,14 +2,14 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['Accuracy', 'BackupAndRestore', 'BleuScore', 'COOTensor', 'CSRTensor', 'Callback', 'CheckpointConfig', 'Cifar100ToMR', 'Cifar10ToMR', 'ConfusionMatrix', 'ConfusionMatrixMetric', 'ConvertModelUtils', 'ConvertNetUtils', 'CosineSimilarity', 'CsvToMR', 'DatasetHelper', 'Dice', 'DynamicLossScaleManager', 'EarlyStopping', 'EnvProfiler', 'F1', 'FAILED', 'Fbeta', 'FileReader', 'FileWriter', 'FixedLossScaleManager', 'GRAPH_MODE', 'HausdorffDistance', 'History', 'ImageNetToMR', 'Int', 'JitConfig', 'LambdaCallback', 'LearningRateScheduler', 'Loss', 'LossMonitor', 'LossScaleManager', 'MAE', 'MSE', 'MeanSurfaceDistance', 'Metric', 'MindPage', 'MnistToMR', 'Model', 'ModelCheckpoint', 'Node', 'NodeType', 'OcclusionSensitivity', 'OnRequestExit', 'PYNATIVE_MODE', 'ParallelMode', 'Parameter', 'ParameterTuple', 'Perplexity', 'Precision', 'Profiler', 'QuantDtype', 'ROC', 'Recall', 'ReduceLROnPlateau', 'RootMeanSquareDistance', 'RowTensor', 'RunContext', 'SUCCESS', 'ScopedValue', 'SparseTensor', 'SummaryCollector', 'SummaryLandscape', 'SummaryRecord', 'SymbolTree', 'TFRecordToMR', 'Tensor', 'TimeMonitor', 'Top1CategoricalAccuracy', 'Top5CategoricalAccuracy', 'TopKCategoricalAccuracy', 'TreeNodeHelper', 'Type', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_c_dataengine', '_c_expression', '_c_mindrecord', '_check_jit_forbidden_api', '_checkparam', '_extends', '_null', '_null_type', '_op_impl', 'absolute_import', 'amp', 'async_ckpt_thread_status', 'auc', 'bool_', 'boost', 'build_searched_strategy', 'build_train_network', 'byte', 'common', 'communication', 'complex128', 'complex64', 'connect_network_with_dataset', 'context', 'convert_model', 'data_sink', 'dataset', 'default_config', 'double', 'dtype', 'dtype_to_nptype', 'dtype_to_pytype', 'experimental', 'export', 'float16', 'float32', 'float64', 'float_', 'get_algo_parameters', 'get_auto_parallel_context', 'get_context', 'get_grad', 'get_level', 'get_log_config', 'get_metric_fn', 'get_obj_module_and_name_info', 'get_ps_context', 'get_py_obj_dtype', 'get_seed', 'grad', 'half', 'int16', 'int32', 'int64', 'int8', 'int_', 'intc', 'intp', 'is_invalid_or_jit_forbidden_method', 'is_jit_forbidden_module', 'jacfwd', 'jacrev', 'jit', 'jit_class', 'jvp', 'list_', 'load', 'load_checkpoint', 'load_distributed_checkpoint', 'load_param_into_net', 'log', 'merge_pipeline_strategys', 'merge_sliced_parameter', 'mindrecord', 'ms_class', 'ms_function', 'ms_memory_recycle', 'mutable', 'names', 'nn', 'number', 'numpy', 'obfuscate_model', 'ops', 'parallel', 'parse_print', 'profiler', 'pytype_to_dtype', 'rank_list_for_transform', 'rearrange_inputs', 'reset_algo_parameters', 'reset_auto_parallel_context', 'reset_ps_context', 'restore_group_info_list', 'rewrite', 'run_check', 'save_checkpoint', 'set_algo_parameters', 'set_auto_parallel_context', 'set_context', 'set_dump', 'set_ps_context', 'set_seed', 'shard', 'short', 'single', 'string', 'tensor', 'tensor_type', 'train', 'transform_checkpoint_by_rank', 'transform_checkpoints', 'tuple_', 'type_none', 'ubyte', 'uint', 'uint16', 'uint32', 'uint64', 'uint8', 'uintc', 'uintp', 'ushort', 'value_and_grad', 'version', 'vjp', 'vmap']\n" + "['Accuracy', 'BackupAndRestore', 'BleuScore', 'COMPATIBLE', 'COOTensor', 'CSRTensor', 'Callback', 'CheckpointConfig', 'Cifar100ToMR', 'Cifar10ToMR', 'ConfusionMatrix', 'ConfusionMatrixMetric', 'ConvertModelUtils', 'ConvertNetUtils', 'CosineSimilarity', 'CsvToMR', 'DatasetHelper', 'Dice', 'DynamicLossScaleManager', 'EarlyStopping', 'EnvProfiler', 'Event', 'ExitByRequest', 'F1', 'FAILED', 'Fbeta', 'FileReader', 'FileWriter', 'FixedLossScaleManager', 'FlopsUtilizationCollector', 'GRAPH_MODE', 'Generator', 'HausdorffDistance', 'History', 'ImageNetToMR', 'Int', 'JitConfig', 'LAX', 'LambdaCallback', 'Layout', 'LearningRateScheduler', 'Loss', 'LossMonitor', 'LossScaleManager', 'MAE', 'MSE', 'MeanSurfaceDistance', 'MemPool', 'Metric', 'MindPage', 'MnistToMR', 'Model', 'ModelCheckpoint', 'Node', 'NodeType', 'OcclusionSensitivity', 'OnRequestExit', 'PYNATIVE_MODE', 'ParallelMode', 'Parameter', 'ParameterTuple', 'Perplexity', 'PluggableAllocator', 'Precision', 'Profiler', 'QuantDtype', 'ROC', 'RSCPluginHandle', 'Recall', 'ReduceLROnPlateau', 'RootMeanSquareDistance', 'RowTensor', 'RunContext', 'STRICT', 'SUCCESS', 'ScopedValue', 'SparseTensor', 'Stream', 'StreamCtx', 'SummaryCollector', 'SummaryLandscape', 'SummaryRecord', 'Symbol', 'SymbolTree', 'TFRecordToMR', 'TFTCommValue', 'Tensor', 'TensorType', 'TimeMonitor', 'Top1CategoricalAccuracy', 'Top5CategoricalAccuracy', 'TopKCategoricalAccuracy', 'TrainFaultTolerance', 'Type', '_Function', '_NullType', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_c_dataengine', '_c_expression', '_c_mindrecord', '_check_jit_forbidden_api', '_checkparam', '_extends', '_no_grad', '_null', '_op_impl', '_reuse_data_ptr', '_tft_handler', 'absolute_import', 'amp', 'arg_dtype_cast', 'arg_handler', 'async_ckpt_thread_status', 'auc', 'bfloat16', 'bool', 'bool_', 'boost', 'build_searched_strategy', 'build_train_network', 'byte', 'cdouble', 'cfloat', 'ckpt_to_safetensors', 'comm_exec_order_check', 'common', 'communication', 'communication_stream', 'complex128', 'complex64', 'connect_network_with_dataset', 'constexpr', 'context', 'current_stream', 'data_sink', 'dataset', 'default_config', 'default_generator', 'default_stream', 'device_context', 'device_manager', 'dispatch_threads_num', 'double', 'dryrun', 'dtype', 'dtype_to_nptype', 'dtype_to_pytype', 'empty_cache', 'enable_dynamic', 'experimental', 'export', 'export_split_mindir', 'float', 'float16', 'float32', 'float64', 'float8_e4m3fn', 'float8_e5m2', 'float_', 'flops_collection', 'from_dlpack', 'from_numpy', 'get_algo_parameters', 'get_auto_parallel_context', 'get_ckpt_path_with_strategy', 'get_context', 'get_current_device', 'get_grad', 'get_level', 'get_log_config', 'get_metric_fn', 'get_obj_module_and_name_info', 'get_ps_context', 'get_py_obj_dtype', 'get_rng_state', 'get_sdc_detect_result', 'get_seed', 'grad', 'graph', 'hal', 'half', 'hifloat8', 'initial_seed', 'int', 'int16', 'int32', 'int64', 'int8', 'int_', 'intc', 'intp', 'is_invalid_or_jit_forbidden_method', 'is_jit_forbidden_module', 'is_tensor', 'jacfwd', 'jacrev', 'jit', 'jit_class', 'jvp', 'launch_blocking', 'lazy_inline', 'list_', 'load', 'load_checkpoint', 'load_checkpoint_async', 'load_distributed_checkpoint', 'load_mindir', 'load_obf_params_into_net', 'load_param_into_net', 'load_segmented_checkpoints', 'log', 'long', 'manual_seed', 'max_memory_allocated', 'max_memory_reserved', 'memory_allocated', 'memory_replay', 'memory_reserved', 'memory_stats', 'memory_summary', 'merge_pipeline_strategys', 'merge_sliced_parameter', 'mindio_preload', 'mindrecord', 'mint', 'ms_memory_recycle', 'mutable', 'names', 'nn', 'no_inline', 'number', 'numpy', 'obfuscate_ckpt', 'onnx', 'ops', 'parallel', 'parameter_broadcast', 'profiler', 'pytype_to_dtype', 'qint4x2', 'rank_list_for_transform', 'rearrange_inputs', 'recompute', 'reset_algo_parameters', 'reset_auto_parallel_context', 'reset_max_memory_allocated', 'reset_max_memory_reserved', 'reset_peak_memory_stats', 'reset_ps_context', 'reshard', 'restore_group_info_list', 'rewrite', 'run_check', 'runtime', 'runtime_execution_order_check', 'safeguard', 'safetensors_to_ckpt', 'save_checkpoint', 'save_mindir', 'sdc_detect_start', 'sdc_detect_stop', 'seed', 'set_algo_parameters', 'set_auto_parallel_context', 'set_context', 'set_cpu_affinity', 'set_cur_stream', 'set_dec_mode', 'set_deterministic', 'set_device', 'set_dump', 'set_enc_key', 'set_enc_mode', 'set_kernel_launch_capture', 'set_kernel_launch_group', 'set_memory', 'set_mindio_server_info', 'set_ps_context', 'set_recursion_limit', 'set_rng_state', 'set_seed', 'shard', 'short', 'single', 'stress_detect', 'string', 'sync_pipeline_shared_parameters', 'synchronize', 'tensor', 'tensor_type', 'to_dlpack', 'tools', 'train', 'transform_checkpoint_by_rank', 'transform_checkpoints', 'tuple_', 'type_none', 'ubyte', 'uint', 'uint16', 'uint32', 'uint64', 'uint8', 'uintc', 'uintp', 'unified_safetensors', 'use_mem_pool', 'ushort', 'utils', 'value_and_grad', 'version', 'vjp', 'vmap']\n" ] } ], @@ -28,33 +28,36 @@ "name": "stdout", "output_type": "stream", "text": [ - "Help on function ones in module mindspore.ops.function.array_func:\n", + "Help on function ones in module mindspore.ops.auto_generate.gen_ops_def:\n", "\n", "ones(shape, dtype=None)\n", " Creates a tensor filled with value ones.\n", " \n", - " Creates a tensor with shape described by the first argument and fills it with value ones in type of the second\n", - " argument.\n", + " .. warning::\n", + " For argument `shape`, Tensor type input will be deprecated in the future version.\n", " \n", " Args:\n", - " shape (Union[tuple[int], int]): The specified shape of output tensor. Only constant positive int is allowed.\n", - " dtype (:class:`mindspore.dtype`): The specified type of output tensor. If `dtype` is None,\n", - " `mindspore.float32` will be used. Default: None.\n", + " shape (Union[tuple[int], list[int], int, Tensor]): The shape specified.\n", + " dtype (:class:`mindspore.dtype`): The data type specified. Default ``None`` .\n", " \n", " Returns:\n", - " Tensor, has the same type and shape as input shape value.\n", - " \n", - " Raises:\n", - " TypeError: If `shape` is neither tuple nor int.\n", + " Tensor\n", " \n", " Supported Platforms:\n", " ``Ascend`` ``GPU`` ``CPU``\n", " \n", " Examples:\n", - " >>> output = ops.ones((2, 2), mindspore.float32)\n", - " >>> print(output)\n", - " [[1. 1.]\n", - " [1. 1.]]\n", + " >>> import mindspore\n", + " >>> mindspore.ops.ones(4)\n", + " Tensor(shape=[4], dtype=Float32, value= [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00])\n", + " >>> mindspore.ops.ones((2, 3))\n", + " Tensor(shape=[2, 3], dtype=Float32, value=\n", + " [[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00],\n", + " [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]])\n", + " >>> mindspore.ops.ones(mindspore.tensor([1, 2, 3]))\n", + " Tensor(shape=[1, 2, 3], dtype=Float32, value=\n", + " [[[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00],\n", + " [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]])\n", "\n" ] } @@ -86,17 +89,81 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function ones in module mindspore.mint:\n", + "\n", + "ones(size, *, dtype=None)\n", + " Creates a tensor filled with value ones.\n", + " \n", + " Creates a tensor with shape described by the first argument and fills it with value ones in type of the second\n", + " argument.\n", + " \n", + " Args:\n", + " size (Union[tuple[int], list[int], int, Tensor]): The specified shape of output tensor. Only positive integer or\n", + " tuple or Tensor containing positive integers are allowed. If it is a Tensor,\n", + " it must be a 0-D or 1-D Tensor with int32 or int64 dtypes.\n", + " \n", + " Keyword Args:\n", + " dtype (:class:`mindspore.dtype`, optional): The specified type of output tensor. If `dtype` is ``None`` ,\n", + " `mindspore.float32` will be used. Default: ``None`` .\n", + " \n", + " Returns:\n", + " Tensor, whose dtype and size are defined by input.\n", + " \n", + " Raises:\n", + " TypeError: If `size` is neither an int nor a tuple/list/Tensor of int.\n", + " \n", + " Supported Platforms:\n", + " ``Ascend`` ``GPU`` ``CPU``\n", + " \n", + " Examples:\n", + " >>> import mindspore\n", + " >>> from mindspore import mint\n", + " >>> output = mint.ones((2, 2), dtype=mindspore.float32)\n", + " >>> print(output)\n", + " [[1. 1.]\n", + " [1. 1.]]\n", + "\n" + ] + } + ], + "source": [ + "from mindspore import mint\n", + "help(mint.ones)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Tensor(shape=[4], dtype=Float32, value= [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00])" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mint.ones(4)" + ] } ], "metadata": { "kernelspec": { - "display_name": "MindSpore", + "display_name": "Python 3.10", "language": "python", - "name": "mindspore" + "name": "py310" }, "language_info": { "codemirror_mode": { @@ -108,7 +175,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.10.14" } }, "nbformat": 4, From df77a181cbb1dcb03134b5ed586e380ecd0c1848 Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Fri, 5 Dec 2025 20:19:54 +0800 Subject: [PATCH 06/12] =?UTF-8?q?ops=E5=8F=98=E6=9B=B4=E4=B8=BAmint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/6_lookup-api.ipynb | 68 --------------------- 1 file changed, 68 deletions(-) diff --git a/chapter_02_preliminaries/6_lookup-api.ipynb b/chapter_02_preliminaries/6_lookup-api.ipynb index e2bf2d7..b542f2d 100644 --- a/chapter_02_preliminaries/6_lookup-api.ipynb +++ b/chapter_02_preliminaries/6_lookup-api.ipynb @@ -19,74 +19,6 @@ "print(dir(mindspore))" ] }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on function ones in module mindspore.ops.auto_generate.gen_ops_def:\n", - "\n", - "ones(shape, dtype=None)\n", - " Creates a tensor filled with value ones.\n", - " \n", - " .. warning::\n", - " For argument `shape`, Tensor type input will be deprecated in the future version.\n", - " \n", - " Args:\n", - " shape (Union[tuple[int], list[int], int, Tensor]): The shape specified.\n", - " dtype (:class:`mindspore.dtype`): The data type specified. Default ``None`` .\n", - " \n", - " Returns:\n", - " Tensor\n", - " \n", - " Supported Platforms:\n", - " ``Ascend`` ``GPU`` ``CPU``\n", - " \n", - " Examples:\n", - " >>> import mindspore\n", - " >>> mindspore.ops.ones(4)\n", - " Tensor(shape=[4], dtype=Float32, value= [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00])\n", - " >>> mindspore.ops.ones((2, 3))\n", - " Tensor(shape=[2, 3], dtype=Float32, value=\n", - " [[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00],\n", - " [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]])\n", - " >>> mindspore.ops.ones(mindspore.tensor([1, 2, 3]))\n", - " Tensor(shape=[1, 2, 3], dtype=Float32, value=\n", - " [[[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00],\n", - " [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]])\n", - "\n" - ] - } - ], - "source": [ - "import mindspore.ops as ops\n", - "help(ops.ones)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Tensor(shape=[4], dtype=Float32, value= [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00])" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ops.ones(4)" - ] - }, { "cell_type": "code", "execution_count": 6, From 1d5168120ecee7aa5c62d4b313b5daa361b6ec04 Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Sat, 6 Dec 2025 18:50:52 +0800 Subject: [PATCH 07/12] Remove empty code cell from 1_pandas.ipynb Removed an empty code cell from the Jupyter notebook. --- chapter_02_preliminaries/1_pandas.ipynb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/chapter_02_preliminaries/1_pandas.ipynb b/chapter_02_preliminaries/1_pandas.ipynb index 0a29ace..96057b7 100644 --- a/chapter_02_preliminaries/1_pandas.ipynb +++ b/chapter_02_preliminaries/1_pandas.ipynb @@ -123,13 +123,6 @@ "print(\"X:\", X)\n", "print(\"y:\", y)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From a623d9816c36beeaf5332c38fcb55a7c47452f7b Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Sat, 6 Dec 2025 21:12:26 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E6=9B=B4=E6=AD=A3=E9=81=97=E6=BC=8F?= =?UTF-8?q?=E7=9A=84ops=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/0_ndarray.ipynb | 104 +++++++++++------------ 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/chapter_02_preliminaries/0_ndarray.ipynb b/chapter_02_preliminaries/0_ndarray.ipynb index 9914b91..1f2d2f6 100644 --- a/chapter_02_preliminaries/0_ndarray.ipynb +++ b/chapter_02_preliminaries/0_ndarray.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -35,7 +35,7 @@ "Tensor(shape=[12], dtype=Int64, value= [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])" ] }, - "execution_count": 33, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -63,7 +63,7 @@ "(12,)" ] }, - "execution_count": 34, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -74,7 +74,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -83,7 +83,7 @@ "12" ] }, - "execution_count": 35, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -106,7 +106,7 @@ " [ 8, 9, 10, 11]])" ] }, - "execution_count": 36, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -118,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -133,7 +133,7 @@ " [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]]])" ] }, - "execution_count": 37, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -144,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -159,7 +159,7 @@ " [ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00]]])" ] }, - "execution_count": 38, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -170,19 +170,19 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Tensor(shape=[3, 4], dtype=Float32, value=\n", - "[[-9.32621598e-01, -1.32283643e-01, 6.06187470e-02, 3.02344084e-01],\n", - " [-3.13425899e-01, -1.18156695e+00, -1.46659148e+00, -1.17737758e+00],\n", - " [-1.85464215e+00, -4.99636263e-01, 1.80253182e-02, -1.73694491e-01]])" + "[[-9.74039912e-01, 8.25895429e-01, 1.92441809e+00, -7.69612253e-01],\n", + " [-7.29935706e-01, -3.04273963e-02, 1.48045754e+00, -5.41354790e-02],\n", + " [ 1.99652505e+00, 1.56677175e+00, 1.07854858e-01, 1.35985911e+00]])" ] }, - "execution_count": 39, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -193,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -205,7 +205,7 @@ " [4, 3, 2, 1]])" ] }, - "execution_count": 40, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -216,7 +216,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -229,7 +229,7 @@ " Tensor(shape=[4], dtype=Float32, value= [ 1.00000000e+00, 4.00000000e+00, 1.60000000e+01, 6.40000000e+01]))" ] }, - "execution_count": 41, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -242,7 +242,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -251,7 +251,7 @@ "Tensor(shape=[4], dtype=Float32, value= [ 2.71828175e+00, 7.38905621e+00, 5.45981483e+01, 2.98095801e+03])" ] }, - "execution_count": 42, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -262,7 +262,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -281,7 +281,7 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01 ... 3.00000000e+00, 2.00000000e+00, 1.00000000e+00]]))" ] }, - "execution_count": 43, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -294,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -306,7 +306,7 @@ " [False, False, False, False]])" ] }, - "execution_count": 44, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -317,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -326,7 +326,7 @@ "Tensor(shape=[], dtype=Float32, value= 66)" ] }, - "execution_count": 45, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -337,7 +337,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -351,7 +351,7 @@ " [[0, 1]]))" ] }, - "execution_count": 46, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -376,7 +376,7 @@ " [2, 3]])" ] }, - "execution_count": 47, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -387,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -399,7 +399,7 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01, 1.10000000e+01]]))" ] }, - "execution_count": 48, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -410,7 +410,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -422,7 +422,7 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01, 1.10000000e+01]])" ] }, - "execution_count": 49, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -434,7 +434,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -446,7 +446,7 @@ " [ 8.00000000e+00, 9.00000000e+00, 1.00000000e+01, 1.10000000e+01]])" ] }, - "execution_count": 50, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -458,7 +458,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -467,7 +467,7 @@ "False" ] }, - "execution_count": 51, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -487,20 +487,20 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "id(Z): 281471574030608\n", - "id(Z): 281471574030608\n" + "id(Z): 281472982009024\n", + "id(Z): 281472982009024\n" ] } ], "source": [ - "Z = ops.zeros_like(Y)\n", + "Z = mint.zeros_like(Y)\n", "print('id(Z):', id(Z))\n", "Z[:] = X + Y\n", "print('id(Z):', id(Z))" @@ -515,7 +515,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -524,7 +524,7 @@ "True" ] }, - "execution_count": 53, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -544,7 +544,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -553,7 +553,7 @@ "(numpy.ndarray, mindspore.common.tensor.Tensor)" ] }, - "execution_count": 54, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -566,7 +566,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -575,7 +575,7 @@ "(Tensor(shape=[1], dtype=Float32, value= [ 3.50000000e+00]), 3.5, 3.5, 3)" ] }, - "execution_count": 55, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } From f141cfcd5892ac6135b070ec42efe8ebfe58e6c0 Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Sat, 6 Dec 2025 21:15:10 +0800 Subject: [PATCH 09/12] Removed empty code cell. --- chapter_02_preliminaries/2_linear-algebra.ipynb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/chapter_02_preliminaries/2_linear-algebra.ipynb b/chapter_02_preliminaries/2_linear-algebra.ipynb index 91fbc6c..8f92ca6 100644 --- a/chapter_02_preliminaries/2_linear-algebra.ipynb +++ b/chapter_02_preliminaries/2_linear-algebra.ipynb @@ -207,7 +207,7 @@ "B == B.T" ] }, - { + {Update execution counts in 0_ndarray.ipynb "cell_type": "code", "execution_count": 11, "metadata": {}, @@ -703,13 +703,6 @@ "source": [ "mint.norm(mint.ones((4, 9)), dim=(0, 1))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 25495b88c241db925382585f29613ad93e8b3a71 Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Sat, 6 Dec 2025 21:17:52 +0800 Subject: [PATCH 10/12] Removed empty code cell. --- chapter_02_preliminaries/2_linear-algebra.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter_02_preliminaries/2_linear-algebra.ipynb b/chapter_02_preliminaries/2_linear-algebra.ipynb index 8f92ca6..57609e8 100644 --- a/chapter_02_preliminaries/2_linear-algebra.ipynb +++ b/chapter_02_preliminaries/2_linear-algebra.ipynb @@ -207,7 +207,7 @@ "B == B.T" ] }, - {Update execution counts in 0_ndarray.ipynb + { "cell_type": "code", "execution_count": 11, "metadata": {}, From 306311b73a07e273c238ee473bd8d97a0bcf995a Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Sat, 6 Dec 2025 21:28:55 +0800 Subject: [PATCH 11/12] =?UTF-8?q?ops=E5=8F=98=E6=9B=B4=E4=B8=BAmint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/5_probability.ipynb | 5208 ++++++++++-------- 1 file changed, 2771 insertions(+), 2437 deletions(-) diff --git a/chapter_02_preliminaries/5_probability.ipynb b/chapter_02_preliminaries/5_probability.ipynb index 0f7a169..7a9367a 100644 --- a/chapter_02_preliminaries/5_probability.ipynb +++ b/chapter_02_preliminaries/5_probability.ipynb @@ -2,28 +2,28 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import mindspore as ms\n", - "import mindspore.ops as ops\n", - "from d2l import mindspore as d2l\n" + "import mindspore.mint as mint\n", + "from d2l import mindspore as d2l" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([0, 1, 0, 0, 0, 0])" + "array([0, 0, 0, 1, 0, 0])" ] }, - "execution_count": 2, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -31,22 +31,22 @@ "source": [ "import numpy as np\n", "\n", - "fair_probs = ops.ones((6)) / 6\n", + "fair_probs = mint.ones((6)) / 6\n", "np.random.multinomial(1, fair_probs)" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([3, 1, 3, 1, 0, 2])" + "array([1, 1, 1, 5, 0, 2])" ] }, - "execution_count": 3, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -57,16 +57,16 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([0.153, 0.161, 0.17 , 0.161, 0.174, 0.181])" + "array([0.169, 0.155, 0.17 , 0.177, 0.177, 0.152])" ] }, - "execution_count": 5, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -87,16 +87,16 @@ "\n", "\n", - "\n", + "\n", " \n", " \n", " \n", " \n", - " 2023-01-16T12:47:46.390146\n", + " 2025-12-06T21:26:34.978422\n", " image/svg+xml\n", " \n", " \n", - " Matplotlib v3.6.3, https://matplotlib.org/\n", + " Matplotlib v3.10.7, https://matplotlib.org/\n", " \n", " \n", " \n", @@ -108,18 +108,18 @@ " \n", " \n", " \n", " \n", " \n", " \n", - " \n", " \n", @@ -127,17 +127,17 @@ " \n", " \n", " \n", - " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -684,17 +684,17 @@ " \n", " \n", " \n", - " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", " \n", " \n", - " \n", " \n", " \n", - " \n", " \n", " \n", - " \n", " \n", " \n", " \n", - " \n", " \n", - " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", + " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", + " \n", + " \n", " \n", " \n", "\n" @@ -3475,9 +3809,9 @@ ], "metadata": { "kernelspec": { - "display_name": "mindspore2.0", + "display_name": "Python 3.10", "language": "python", - "name": "mindspore2.0" + "name": "py310" }, "language_info": { "codemirror_mode": { @@ -3489,7 +3823,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.15" + "version": "3.10.14" } }, "nbformat": 4, From c898938dc8cd0e50c1bd51694ea2768205891f1f Mon Sep 17 00:00:00 2001 From: Y-yyyyq <648203301@qq.com> Date: Sat, 6 Dec 2025 22:08:17 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E6=9B=B4=E6=AD=A3=E9=81=97=E6=BC=8F?= =?UTF-8?q?=E7=9A=84ops=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chapter_02_preliminaries/0_ndarray.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter_02_preliminaries/0_ndarray.ipynb b/chapter_02_preliminaries/0_ndarray.ipynb index 1f2d2f6..d4896f5 100644 --- a/chapter_02_preliminaries/0_ndarray.ipynb +++ b/chapter_02_preliminaries/0_ndarray.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "首先,我们导入`mindspore`。此外,需要导入`mindspore`的`ops`API来完成部分操作。" + "首先,我们导入`mindspore`。此外,需要导入`mindspore`的`mint`API来完成部分操作。" ] }, {