{"id":43021,"date":"2025-07-29T18:21:08","date_gmt":"2025-07-29T09:21:08","guid":{"rendered":"https:\/\/techgym.jp\/?p=43021"},"modified":"2025-07-29T18:21:10","modified_gmt":"2025-07-29T09:21:10","slug":"python-numpy","status":"publish","type":"post","link":"https:\/\/techgym.jp\/column\/python-numpy\/","title":{"rendered":"Python NumPy\u5b8c\u5168\u653b\u7565\u3010\u914d\u5217\u64cd\u4f5c\u30fb\u6570\u5024\u8a08\u7b97\u3092\u5fb9\u5e95\u30de\u30b9\u30bf\u30fc\u3011"},"content":{"rendered":"\n<p>\u00a0<\/p>\n<p>NumPy\uff08Numerical Python\uff09\u306f\u3001Python\u3067\u6570\u5024\u8a08\u7b97\u3092\u884c\u3046\u305f\u3081\u306e\u6700\u3082\u91cd\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u6a5f\u68b0\u5b66\u7fd2\u3001\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u3001\u79d1\u5b66\u8a08\u7b97\u306e\u57fa\u76e4\u3068\u3057\u3066\u5e83\u304f\u4f7f\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001NumPy\u306e\u57fa\u672c\u304b\u3089\u5fdc\u7528\u307e\u3067\u3001\u5b9f\u7528\u7684\u306a\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3068\u3068\u3082\u306b\u5fb9\u5e95\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>NumPy\u3068\u306f<\/h2>\n<p>NumPy\u306f\u3001\u591a\u6b21\u5143\u914d\u5217\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u914d\u5217\u3092\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\u7fa4\u3092\u63d0\u4f9b\u3059\u308bPython\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u4e3b\u306a\u7279\u5fb4\uff1a<\/p>\n<ul>\n<li>\u9ad8\u901f\u306a\u591a\u6b21\u5143\u914d\u5217\u64cd\u4f5c<\/li>\n<li>\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c6\u30a3\u30f3\u30b0\u6a5f\u80fd<\/li>\n<li>\u7dda\u5f62\u4ee3\u6570\u95a2\u6570<\/li>\n<li>\u30d5\u30fc\u30ea\u30a8\u5909\u63db<\/li>\n<li>\u4e71\u6570\u751f\u6210\u6a5f\u80fd<\/li>\n<li>C\/C++\/Fortran\u30b3\u30fc\u30c9\u3068\u306e\u7d71\u5408<\/li>\n<\/ul>\n<h2>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u57fa\u672c\u8a2d\u5b9a<\/h2>\n<pre><code class=\"language-bash\"># NumPy\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\npip install numpy\n\n# \u6570\u5024\u8a08\u7b97\u95a2\u9023\u30e9\u30a4\u30d6\u30e9\u30ea\u3082\u4e00\u7dd2\u306b\npip install numpy scipy matplotlib pandas\n<\/code><\/pre>\n<pre><code class=\"language-python\">import numpy as np\nprint(np.__version__)  # \u30d0\u30fc\u30b8\u30e7\u30f3\u78ba\u8a8d\n<\/code><\/pre>\n<h2>NumPy\u914d\u5217\u306e\u57fa\u672c<\/h2>\n<h3>\u914d\u5217\u306e\u4f5c\u6210<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u30ea\u30b9\u30c8\u304b\u3089\u914d\u5217\u4f5c\u6210\narr1 = np.array([1, 2, 3, 4, 5])\narr2 = np.array([[1, 2, 3], [4, 5, 6]])\nprint(arr1)  # [1 2 3 4 5]\nprint(arr2.shape)  # (2, 3)\n<\/code><\/pre>\n<h3>\u7279\u6b8a\u306a\u914d\u5217\u306e\u751f\u6210<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u30bc\u30ed\u914d\u5217\u30011\u914d\u5217\nzeros = np.zeros((3, 4))\nones = np.ones((2, 3))\nempty = np.empty((2, 2))\n\n# \u9023\u7d9a\u5024\u3001\u7b49\u9593\u9694\u914d\u5217\nrange_arr = np.arange(0, 10, 2)  # [0 2 4 6 8]\nlinspace_arr = np.linspace(0, 1, 5)  # [0. 0.25 0.5 0.75 1.]\n<\/code><\/pre>\n<h3>\u914d\u5217\u306e\u5c5e\u6027<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([[1, 2, 3], [4, 5, 6]])\nprint(f\"\u5f62\u72b6: {arr.shape}\")      # (2, 3)\nprint(f\"\u6b21\u5143\u6570: {arr.ndim}\")     # 2\nprint(f\"\u8981\u7d20\u6570: {arr.size}\")     # 6\nprint(f\"\u30c7\u30fc\u30bf\u578b: {arr.dtype}\")  # int64\n<\/code><\/pre>\n<h2>\u914d\u5217\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3068\u30b9\u30e9\u30a4\u30b9<\/h2>\n<h3>\u57fa\u672c\u7684\u306a\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([10, 20, 30, 40, 50])\nprint(arr[0])    # 10\nprint(arr[-1])   # 50\nprint(arr[1:4])  # [20 30 40]\n<\/code><\/pre>\n<h3>\u591a\u6b21\u5143\u914d\u5217\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\nprint(arr[0, 1])     # 2\nprint(arr[1, :])     # [4 5 6]\nprint(arr[:, 2])     # [3 6 9]\nprint(arr[0:2, 1:3]) # [[2 3] [5 6]]\n<\/code><\/pre>\n<h3>\u30d6\u30fc\u30eb\u578b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([1, 2, 3, 4, 5, 6])\nmask = arr &gt; 3\nprint(arr[mask])  # [4 5 6]\nprint(arr[arr % 2 == 0])  # [2 4 6]\n<\/code><\/pre>\n<h2>\u914d\u5217\u306e\u5f62\u72b6\u64cd\u4f5c<\/h2>\n<h3>reshape\uff08\u5f62\u72b6\u5909\u66f4\uff09<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.arange(12)\nreshaped = arr.reshape(3, 4)\nprint(reshaped.shape)  # (3, 4)\n\n# -1\u3092\u4f7f\u3063\u305f\u81ea\u52d5\u8a08\u7b97\nauto_shaped = arr.reshape(4, -1)  # (4, 3)\n<\/code><\/pre>\n<h3>\u914d\u5217\u306e\u7d50\u5408\u3068\u5206\u5272<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr1 = np.array([1, 2, 3])\narr2 = np.array([4, 5, 6])\n\n# \u7d50\u5408\nconcat = np.concatenate([arr1, arr2])  # [1 2 3 4 5 6]\nvstack = np.vstack([arr1, arr2])       # [[1 2 3] [4 5 6]]\nhstack = np.hstack([arr1, arr2])       # [1 2 3 4 5 6]\n\n# \u5206\u5272\nsplit_arr = np.split(np.arange(6), 3)  # [array([0, 1]), array([2, 3]), array([4, 5])]\n<\/code><\/pre>\n<h2>\u6570\u5b66\u95a2\u6570\u3068\u7d71\u8a08\u95a2\u6570<\/h2>\n<h3>\u57fa\u672c\u7684\u306a\u6570\u5b66\u95a2\u6570<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([1, 2, 3, 4, 5])\nprint(np.sum(arr))    # 15\nprint(np.mean(arr))   # 3.0\nprint(np.std(arr))    # 1.4142135623730951\nprint(np.max(arr))    # 5\nprint(np.min(arr))    # 1\n<\/code><\/pre>\n<h3>\u4e09\u89d2\u95a2\u6570\u3068\u6307\u6570\u95a2\u6570<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\nangles = np.array([0, np.pi\/4, np.pi\/2, np.pi])\nprint(np.sin(angles))  # [0. 0.707 1. 0.]\nprint(np.cos(angles))  # [1. 0.707 0. -1.]\n\nx = np.array([1, 2, 3])\nprint(np.exp(x))   # [2.718 7.389 20.086]\nprint(np.log(x))   # [0. 0.693 1.099]\n<\/code><\/pre>\n<h3>\u8ef8\u3092\u6307\u5b9a\u3057\u305f\u7d71\u8a08\u8a08\u7b97<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([[1, 2, 3], [4, 5, 6]])\nprint(np.sum(arr, axis=0))    # [5 7 9] (\u7e26\u65b9\u5411\u306e\u5408\u8a08)\nprint(np.sum(arr, axis=1))    # [6 15] (\u6a2a\u65b9\u5411\u306e\u5408\u8a08)\nprint(np.mean(arr, axis=0))   # [2.5 3.5 4.5]\n<\/code><\/pre>\n<h2>\u7dda\u5f62\u4ee3\u6570<\/h2>\n<h3>\u884c\u5217\u306e\u57fa\u672c\u6f14\u7b97<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\nA = np.array([[1, 2], [3, 4]])\nB = np.array([[5, 6], [7, 8]])\n\n# \u884c\u5217\u7a4d\nproduct = np.dot(A, B)  # \u307e\u305f\u306f A @ B\nprint(product)  # [[19 22] [43 50]]\n\n# \u8ee2\u7f6e\ntranspose = A.T\nprint(transpose)  # [[1 3] [2 4]]\n<\/code><\/pre>\n<h3>\u56fa\u6709\u5024\u3068\u56fa\u6709\u30d9\u30af\u30c8\u30eb<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\nA = np.array([[4, 2], [1, 3]])\neigenvalues, eigenvectors = np.linalg.eig(A)\nprint(f\"\u56fa\u6709\u5024: {eigenvalues}\")\nprint(f\"\u56fa\u6709\u30d9\u30af\u30c8\u30eb:\\n{eigenvectors}\")\n<\/code><\/pre>\n<h3>\u9023\u7acb\u65b9\u7a0b\u5f0f\u306e\u89e3\u6cd5<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# Ax = b \u306e\u89e3\u3092\u6c42\u3081\u308b\nA = np.array([[2, 1], [1, 3]])\nb = np.array([8, 13])\nx = np.linalg.solve(A, b)\nprint(x)  # [1. 6.]\n<\/code><\/pre>\n<h2>\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c6\u30a3\u30f3\u30b0<\/h2>\n<h3>\u57fa\u672c\u7684\u306a\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c6\u30a3\u30f3\u30b0<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([[1, 2, 3], [4, 5, 6]])\nscalar = 10\n\n# \u30b9\u30ab\u30e9\u30fc\u3068\u306e\u6f14\u7b97\nresult = arr + scalar  # [[11 12 13] [14 15 16]]\nprint(result)\n\n# \u7570\u306a\u308b\u5f62\u72b6\u306e\u914d\u5217\u3068\u306e\u6f14\u7b97\nvec = np.array([1, 2, 3])\nresult2 = arr + vec  # [[2 4 6] [5 7 9]]\nprint(result2)\n<\/code><\/pre>\n<h3>\u9ad8\u5ea6\u306a\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c6\u30a3\u30f3\u30b0<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.arange(12).reshape(4, 3)\nrow_means = np.mean(arr, axis=1, keepdims=True)\ncentered = arr - row_means  # \u5404\u884c\u306e\u5e73\u5747\u3092\u5f15\u304f\nprint(centered)\n<\/code><\/pre>\n<h2>\u4e71\u6570\u751f\u6210<\/h2>\n<h3>\u57fa\u672c\u7684\u306a\u4e71\u6570\u751f\u6210<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# 0-1\u306e\u4e00\u69d8\u5206\u5e03\nuniform = np.random.rand(3, 3)\n\n# \u6a19\u6e96\u6b63\u898f\u5206\u5e03\nnormal = np.random.randn(5)\n\n# \u6574\u6570\u306e\u4e71\u6570\nintegers = np.random.randint(1, 100, size=10)\nprint(integers)\n<\/code><\/pre>\n<h3>\u518d\u73fe\u53ef\u80fd\u306a\u4e71\u6570<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u30b7\u30fc\u30c9\u8a2d\u5b9a\nnp.random.seed(42)\nrandom_data = np.random.rand(5)\nprint(random_data)\n\n# \u65b0\u3057\u3044Generator\u3092\u4f7f\u7528\uff08\u63a8\u5968\uff09\nrng = np.random.default_rng(42)\nrandom_data2 = rng.random(5)\nprint(random_data2)\n<\/code><\/pre>\n<h2>\u5b9f\u7528\u7684\u306a\u5fdc\u7528\u4f8b<\/h2>\n<h3>\u30c7\u30fc\u30bf\u5206\u6790\u3067\u306e\u6d3b\u7528<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u58f2\u4e0a\u30c7\u30fc\u30bf\u306e\u5206\u6790\nsales = np.array([100, 150, 200, 180, 220, 190, 250])\nprint(f\"\u5e73\u5747\u58f2\u4e0a: {np.mean(sales):.1f}\")\nprint(f\"\u58f2\u4e0a\u306e\u6a19\u6e96\u504f\u5dee: {np.std(sales):.1f}\")\nprint(f\"\u6700\u5927\u58f2\u4e0a: {np.max(sales)}\")\nprint(f\"\u6210\u9577\u7387: {(sales[-1] \/ sales[0] - 1) * 100:.1f}%\")\n<\/code><\/pre>\n<h3>\u753b\u50cf\u51e6\u7406\u3067\u306e\u5fdc\u7528<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u753b\u50cf\u30c7\u30fc\u30bf\u306e\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\uff08\u30b0\u30ec\u30fc\u30b9\u30b1\u30fc\u30eb\uff09\nimage = np.random.randint(0, 256, size=(100, 100), dtype=np.uint8)\n\n# \u753b\u50cf\u306e\u57fa\u672c\u7d71\u8a08\nprint(f\"\u753b\u50cf\u30b5\u30a4\u30ba: {image.shape}\")\nprint(f\"\u5e73\u5747\u8f1d\u5ea6: {np.mean(image):.1f}\")\nprint(f\"\u6700\u5927\u8f1d\u5ea6: {np.max(image)}\")\n\n# \u4e8c\u5024\u5316\nbinary_image = (image &gt; 128).astype(np.uint8) * 255\n<\/code><\/pre>\n<h3>\u4fe1\u53f7\u51e6\u7406\u3067\u306e\u5fdc\u7528<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u30b5\u30a4\u30f3\u6ce2\u306e\u751f\u6210\nt = np.linspace(0, 2*np.pi, 1000)\nsignal = np.sin(5*t) + 0.5*np.sin(10*t)\n\n# \u30ce\u30a4\u30ba\u8ffd\u52a0\nnoisy_signal = signal + 0.1*np.random.randn(len(signal))\n\n# \u57fa\u672c\u7d71\u8a08\nprint(f\"\u4fe1\u53f7\u306e\u5e73\u5747: {np.mean(signal):.3f}\")\nprint(f\"\u4fe1\u53f7\u306eRMS: {np.sqrt(np.mean(signal**2)):.3f}\")\n<\/code><\/pre>\n<h2>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6700\u9069\u5316<\/h2>\n<h3>\u30d9\u30af\u30c8\u30eb\u5316\u306e\u91cd\u8981\u6027<\/h3>\n<pre><code class=\"language-python\">import numpy as np\nimport time\n\n# \u975e\u52b9\u7387\u306a\u65b9\u6cd5\uff08Python\u30eb\u30fc\u30d7\uff09\ndef slow_sum(arr):\n    result = 0\n    for i in range(len(arr)):\n        result += arr[i] ** 2\n    return result\n\n# \u52b9\u7387\u7684\u306a\u65b9\u6cd5\uff08NumPy\u30d9\u30af\u30c8\u30eb\u5316\uff09\ndef fast_sum(arr):\n    return np.sum(arr ** 2)\n\n# \u6027\u80fd\u6bd4\u8f03\nlarge_array = np.random.rand(1000000)\n\nstart = time.time()\nslow_result = slow_sum(large_array)\nslow_time = time.time() - start\n\nstart = time.time()\nfast_result = fast_sum(large_array)\nfast_time = time.time() - start\n\nprint(f\"\u9045\u3044\u65b9\u6cd5: {slow_time:.3f}\u79d2\")\nprint(f\"\u901f\u3044\u65b9\u6cd5: {fast_time:.3f}\u79d2\")\nprint(f\"\u901f\u5ea6\u5411\u4e0a: {slow_time\/fast_time:.1f}\u500d\")\n<\/code><\/pre>\n<h3>\u30e1\u30e2\u30ea\u52b9\u7387\u7684\u306a\u64cd\u4f5c<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# in-place\u6f14\u7b97\u3067\u30e1\u30e2\u30ea\u7bc0\u7d04\narr = np.random.rand(1000, 1000)\narr += 1  # arr = arr + 1 \u3088\u308a\u30e1\u30e2\u30ea\u52b9\u7387\u304c\u826f\u3044\narr *= 2  # arr = arr * 2 \u3088\u308a\u30e1\u30e2\u30ea\u52b9\u7387\u304c\u826f\u3044\n\n# view\u3068copy\u306e\u4f7f\u3044\u5206\u3051\nview = arr[::2, ::2]  # \u30e1\u30e2\u30ea\u3092\u5171\u6709\u3059\u308bview\ncopy = arr[::2, ::2].copy()  # \u72ec\u7acb\u3057\u305fcopy\n<\/code><\/pre>\n<h2>\u9ad8\u5ea6\u306a\u6a5f\u80fd<\/h2>\n<h3>\u69cb\u9020\u5316\u914d\u5217<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u69cb\u9020\u5316\u914d\u5217\u306e\u5b9a\u7fa9\ndtype = [('name', 'U10'), ('age', 'i4'), ('salary', 'f8')]\nemployees = np.array([\n    ('Alice', 25, 50000.0),\n    ('Bob', 30, 60000.0),\n    ('Charlie', 35, 70000.0)\n], dtype=dtype)\n\nprint(employees['name'])    # ['Alice' 'Bob' 'Charlie']\nprint(employees['salary'])  # [50000. 60000. 70000.]\n<\/code><\/pre>\n<h3>\u30de\u30b9\u30af\u914d\u5217<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u6b20\u640d\u5024\u3092\u542b\u3080\u30c7\u30fc\u30bf\u306e\u51e6\u7406\ndata = np.array([1, 2, -999, 4, 5, -999, 7])\nmasked_data = np.ma.masked_equal(data, -999)\nprint(f\"\u5e73\u5747: {np.ma.mean(masked_data):.1f}\")  # -999\u3092\u9664\u5916\u3057\u305f\u5e73\u5747\n<\/code><\/pre>\n<h3>\u30e6\u30cb\u30d0\u30fc\u30b5\u30eb\u95a2\u6570\uff08ufunc\uff09<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u30ab\u30b9\u30bf\u30e0ufunc\u306e\u4f5c\u6210\ndef custom_func(x, y):\n    return x**2 + y**2\n\nvectorized_func = np.vectorize(custom_func)\nresult = vectorized_func([1, 2, 3], [4, 5, 6])\nprint(result)  # [17 29 45]\n<\/code><\/pre>\n<h2>\u30c7\u30fc\u30bf\u578b\u3068\u578b\u5909\u63db<\/h2>\n<h3>\u30c7\u30fc\u30bf\u578b\u306e\u6307\u5b9a<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u660e\u793a\u7684\u306a\u30c7\u30fc\u30bf\u578b\u6307\u5b9a\nint_arr = np.array([1, 2, 3], dtype=np.int32)\nfloat_arr = np.array([1, 2, 3], dtype=np.float64)\nbool_arr = np.array([True, False, True], dtype=np.bool_)\n\nprint(f\"int32\u306e\u30b5\u30a4\u30ba: {int_arr.itemsize}\u30d0\u30a4\u30c8\")\nprint(f\"float64\u306e\u30b5\u30a4\u30ba: {float_arr.itemsize}\u30d0\u30a4\u30c8\")\n<\/code><\/pre>\n<h3>\u578b\u5909\u63db<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([1.7, 2.8, 3.9])\nint_arr = arr.astype(np.int32)    # [1 2 3]\nstr_arr = arr.astype(str)         # ['1.7' '2.8' '3.9']\nprint(int_arr)\nprint(str_arr)\n<\/code><\/pre>\n<h2>\u30d5\u30a1\u30a4\u30eb\u5165\u51fa\u529b<\/h2>\n<h3>NumPy\u5f62\u5f0f\u3067\u306e\u4fdd\u5b58\u30fb\u8aad\u307f\u8fbc\u307f<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u914d\u5217\u306e\u4fdd\u5b58\narr = np.array([[1, 2, 3], [4, 5, 6]])\nnp.save('array.npy', arr)\nnp.savez('arrays.npz', a=arr, b=arr*2)  # \u8907\u6570\u914d\u5217\n\n# \u914d\u5217\u306e\u8aad\u307f\u8fbc\u307f\nloaded_arr = np.load('array.npy')\nloaded_arrays = np.load('arrays.npz')\nprint(loaded_arrays['a'])\n<\/code><\/pre>\n<h3>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3067\u306e\u5165\u51fa\u529b<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# CSV\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\ndata = np.loadtxt('data.csv', delimiter=',', skiprows=1)\n\n# \u30c7\u30fc\u30bf\u306e\u4fdd\u5b58\nresult = np.array([[1, 2, 3], [4, 5, 6]])\nnp.savetxt('output.csv', result, delimiter=',', fmt='%.2f')\n<\/code><\/pre>\n<h2>\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3068\u30c7\u30d0\u30c3\u30b0<\/h2>\n<h3>\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u3068\u5bfe\u51e6\u6cd5<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\ntry:\n    # \u5f62\u72b6\u4e0d\u4e00\u81f4\u30a8\u30e9\u30fc\u306e\u5bfe\u51e6\n    a = np.array([[1, 2], [3, 4]])\n    b = np.array([1, 2, 3])\n    result = a + b  # \u30a8\u30e9\u30fc\u304c\u767a\u751f\nexcept ValueError as e:\n    print(f\"\u5f62\u72b6\u30a8\u30e9\u30fc: {e}\")\n    b_reshaped = b[:2].reshape(-1, 1)  # \u5f62\u72b6\u3092\u8abf\u6574\n    result = a + b_reshaped\n    print(result)\n<\/code><\/pre>\n<h3>\u6570\u5024\u8a08\u7b97\u306e\u6ce8\u610f\u70b9<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\n# \u6d6e\u52d5\u5c0f\u6570\u70b9\u7cbe\u5ea6\u306e\u554f\u984c\na = np.array([0.1, 0.2, 0.3])\nprint(np.sum(a) == 0.6)  # False\n\n# \u89e3\u6c7a\u6cd5\uff1a\u8a31\u5bb9\u8aa4\u5dee\u3092\u4f7f\u3063\u305f\u6bd4\u8f03\nprint(np.allclose(np.sum(a), 0.6))  # True\n\n# \u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u5bfe\u7b56\nlarge_numbers = np.array([1e308, 1e308])\nsafe_sum = np.sum(large_numbers, dtype=np.float64)\n<\/code><\/pre>\n<h2>\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u6bd4\u8f03\u8868<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u64cd\u4f5c<\/th>\n<th>Python\u30ea\u30b9\u30c8<\/th>\n<th>NumPy\u914d\u5217<\/th>\n<th>\u901f\u5ea6\u5411\u4e0a<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8981\u7d20\u30a2\u30af\u30bb\u30b9<\/td>\n<td>1x<\/td>\n<td>1x<\/td>\n<td>\u540c\u7b49<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u5b66\u6f14\u7b97<\/td>\n<td>1x<\/td>\n<td>10-100x<\/td>\n<td>\u5927\u5e45\u5411\u4e0a<\/td>\n<\/tr>\n<tr>\n<td>\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf<\/td>\n<td>1x<\/td>\n<td>0.1-0.3x<\/td>\n<td>\u5927\u5e45\u524a\u6e1b<\/td>\n<\/tr>\n<tr>\n<td>\u5927\u91cf\u30c7\u30fc\u30bf\u51e6\u7406<\/td>\n<td>1x<\/td>\n<td>50-200x<\/td>\n<td>\u5287\u7684\u5411\u4e0a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>NumPy\u306f\u3001Python\u3067\u6570\u5024\u8a08\u7b97\u3092\u884c\u3046\u969b\u306e\u5fc5\u9808\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u52b9\u7387\u7684\u306a\u914d\u5217\u64cd\u4f5c\u3001\u8c4a\u5bcc\u306a\u6570\u5b66\u95a2\u6570\u3001\u7dda\u5f62\u4ee3\u6570\u6a5f\u80fd\u306b\u3088\u308a\u3001\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u3084\u6a5f\u68b0\u5b66\u7fd2\u306e\u57fa\u76e4\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\uff1a<\/p>\n<ul>\n<li><strong>\u30d9\u30af\u30c8\u30eb\u5316<\/strong>\u3067\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u6700\u5927\u5316<\/li>\n<li><strong>\u30d6\u30ed\u30fc\u30c9\u30ad\u30e3\u30b9\u30c6\u30a3\u30f3\u30b0<\/strong>\u3067\u67d4\u8edf\u306a\u914d\u5217\u64cd\u4f5c<\/li>\n<li><strong>\u9069\u5207\u306a\u30c7\u30fc\u30bf\u578b<\/strong>\u3067\u30e1\u30e2\u30ea\u52b9\u7387\u3092\u5411\u4e0a<\/li>\n<li><strong>in-place\u6f14\u7b97<\/strong>\u3067\u30e1\u30e2\u30ea\u4f7f\u7528\u91cf\u3092\u524a\u6e1b<\/li>\n<\/ul>\n<p>\u672c\u8a18\u4e8b\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u53c2\u8003\u306b\u3001NumPy\u3092\u4f7f\u3063\u305f\u52b9\u7387\u7684\u306a\u6570\u5024\u8a08\u7b97\u30b7\u30b9\u30c6\u30e0\u3092\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u7d99\u7d9a\u7684\u306a\u5b66\u7fd2\u306b\u3088\u308a\u3001\u3088\u308a\u9ad8\u5ea6\u306a\u30c7\u30fc\u30bf\u51e6\u7406\u6280\u8853\u3092\u8eab\u306b\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u53c2\u8003\u6587\u732e<\/h2>\n<ul>\n<li>NumPy\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/li>\n<li>NumPy User Guide<\/li>\n<li>Scientific Python Ecosystem<\/li>\n<li>Linear Algebra with NumPy<\/li>\n<\/ul>\n\n\n\n<p>\u25a0\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"3UYsxPgLZP\"><a href=\"https:\/\/techgym.jp\/column\/ori-app\/\">\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30d7\u30ed\u30f3\u30d7\u30c8\u3060\u3051\u3067\u30aa\u30ea\u30b8\u30ca\u30eb\u30a2\u30d7\u30ea\u3092\u958b\u767a\u30fb\u516c\u958b\u3057\u3066\u307f\u305f\uff01\uff01&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/column\/ori-app\/embed\/#?secret=GoF8XyZuE0#?secret=3UYsxPgLZP\" data-secret=\"3UYsxPgLZP\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u25a0AI\u6642\u4ee3\u306e\u7b2c\u4e00\u6b69\uff01\u300cAI\u99c6\u52d5\u958b\u767a\u30b3\u30fc\u30b9\u300d\u306f\u3058\u3081\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<p>\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821\u3067\u5148\u884c\u958b\u59cb\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"IwlVaL3wMv\"><a href=\"https:\/\/techgym.jp\/about\/ai-driven-development\/\">AI\u6642\u4ee3\u306e\u7b2c\u4e00\u6b69\uff01\u300cAI\u99c6\u52d5\u958b\u767a\u30b3\u30fc\u30b9\u300d\uff08\u521d\u5fc3\u8005\u5411\u3051\uff09<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;AI\u6642\u4ee3\u306e\u7b2c\u4e00\u6b69\uff01\u300cAI\u99c6\u52d5\u958b\u767a\u30b3\u30fc\u30b9\u300d\uff08\u521d\u5fc3\u8005\u5411\u3051\uff09&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/about\/ai-driven-development\/embed\/#?secret=pHGZYaXIUr#?secret=IwlVaL3wMv\" data-secret=\"IwlVaL3wMv\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u25a0\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821<\/p>\n\n\n\n<p>\u300c\u6b66\u7530\u587e\u300d\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u7248\u3068\u3044\u3048\u3070\u300c\u30c6\u30c3\u30af\u30b8\u30e0\u300d\u3002<br>\u8b1b\u7fa9\u52d5\u753b\u306a\u3057\u3001\u6559\u79d1\u66f8\u306a\u3057\u3002\u300c\u9032\u6357\u7ba1\u7406\u3068\u30b3\u30fc\u30c1\u30f3\u30b0\u300d\u3067\u52b9\u7387\u5b66\u7fd2\u3002<br>\u3088\u308a\u65e9\u304f\u3001\u3088\u308a\u5b89\u304f\u3001\u3057\u304b\u3082\u5bfe\u9762\u578b\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\u3067\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"Q0YoJdHyxt\"><a href=\"https:\/\/techgym.jp\/tokyo\/tokyo_honko\/\">\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30c6\u30c3\u30af\u30b8\u30e0\u6771\u4eac\u672c\u6821&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/tokyo\/tokyo_honko\/embed\/#?secret=I46ETlm7CH#?secret=Q0YoJdHyxt\" data-secret=\"Q0YoJdHyxt\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u77ed\u671f\u8b1b\u7fd2\uff1e5\u65e5\u30675\u4e07\u5186\u306e\u300cPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u958b\u50ac\u4e2d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"H9tqCFsgSG\"><a href=\"https:\/\/techgym.jp\/event\/nagatacho_camp\/\">\u72ec\u5b66\u3082\u30aa\u30f3\u30e9\u30a4\u30f3\u3082\u7121\u7406\u3060\u304b\u3089\u3001\u6709\u7d66\u3068\u3063\u3066\u300cPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u3078\u30105\u65e5\u9593\u30675\u4e07\u5186\u3011<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u72ec\u5b66\u3082\u30aa\u30f3\u30e9\u30a4\u30f3\u3082\u7121\u7406\u3060\u304b\u3089\u3001\u6709\u7d66\u3068\u3063\u3066\u300cPython\u30df\u30cb\u30ad\u30e3\u30f3\u30d7\u300d\u3078\u30105\u65e5\u9593\u30675\u4e07\u5186\u3011&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/event\/nagatacho_camp\/embed\/#?secret=YkZIJUsy1T#?secret=H9tqCFsgSG\" data-secret=\"H9tqCFsgSG\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u67081\u958b\u50ac\uff1e\u653e\u9001\u4f5c\u5bb6\u306b\u3088\u308b\u6620\u50cf\u30c7\u30a3\u30ec\u30af\u30bf\u30fc\u990a\u6210\u8b1b\u5ea7<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"6YDvfJNq2P\"><a href=\"https:\/\/techgym.jp\/event\/video_director\/\">\u73fe\u5f79\u653e\u9001\u4f5c\u5bb6\u304c\u6559\u3048\u308b\u52d5\u753b\u8b1b\u5ea7\uff01\u300e\uff24\uff2f\uff27\uff21\u300f<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u73fe\u5f79\u653e\u9001\u4f5c\u5bb6\u304c\u6559\u3048\u308b\u52d5\u753b\u8b1b\u5ea7\uff01\u300e\uff24\uff2f\uff27\uff21\u300f&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/event\/video_director\/embed\/#?secret=vVg3CnuNKH#?secret=6YDvfJNq2P\" data-secret=\"6YDvfJNq2P\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\uff1c\u30aa\u30f3\u30e9\u30a4\u30f3\u7121\u6599\uff1e\u30bc\u30ed\u304b\u3089\u59cb\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"AfKgObnFDX\"><a href=\"https:\/\/techgym.jp\/tokyo_python\/\">\u30bc\u30ed\u304b\u3089\u59cb\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7\uff08\u7406\u7cfb\u30fb\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u521d\u5fc3\u8005\u5411\u3051\uff09<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; visibility: hidden;\" title=\"&#8220;\u30bc\u30ed\u304b\u3089\u59cb\u3081\u308bPython\u7206\u901f\u8b1b\u5ea7\uff08\u7406\u7cfb\u30fb\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u521d\u5fc3\u8005\u5411\u3051\uff09&#8221; &#8212; \u3010\u30c6\u30c3\u30af\u30b8\u30e0\u3011\u683c\u5b89\u30fb\u5bfe\u9762\u578b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb\" src=\"https:\/\/techgym.jp\/tokyo_python\/embed\/#?secret=sXkqBLgdpJ#?secret=AfKgObnFDX\" data-secret=\"AfKgObnFDX\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 NumPy\uff08Numerical Python\uff09\u306f\u3001Python\u3067\u6570\u5024\u8a08\u7b97\u3092\u884c\u3046\u305f\u3081\u306e\u6700\u3082\u91cd\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u6a5f\u68b0\u5b66\u7fd2\u3001\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u3001\u79d1\u5b66\u8a08\u7b97\u306e\u57fa\u76e4\u3068\u3057\u3066\u5e83\u304f\u4f7f\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001NumPy\u306e\u57fa\u672c\u304b\u3089\u5fdc\u7528 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":42501,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-43021","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-column"],"views":54,"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/07\/f3403acf5c65aedec0dba821c4c26404.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts\/43021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/comments?post=43021"}],"version-history":[{"count":0,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/posts\/43021\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/media\/42501"}],"wp:attachment":[{"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/media?parent=43021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/categories?post=43021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techgym.jp\/wp-json\/wp\/v2\/tags?post=43021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}