【深度学习实验】NumPy的简单用法

目录

一、NumPy介绍

[1. 官网](#1. 官网)

[2. 官方教程](#2. 官方教程)

二、实验内容

[1. 导入numpy库](#1. 导入numpy库)

[2. 打印版本号](#2. 打印版本号)

[3. arange 函数](#3. arange 函数)

[4. array函数](#4. array函数)

[5. reshape函数](#5. reshape函数)

[6. 矩阵点乘(逐元素相乘)](#6. 矩阵点乘(逐元素相乘))

[7. 矩阵乘法](#7. 矩阵乘法)


一、NumPy介绍

NumPy是一个常用于科学计算的Python库,尤其在深度学习和机器学习中应用广泛。

1. 官网

NumPyhttps://numpy.org/

2. 官方教程

NumPy:初学者的绝对基础知识 --- NumPy v1.25 手册https://numpy.org/doc/stable/user/absolute_beginners.html

二、实验内容

1. 导入numpy库

  • Import numpy library (you should follow the standard NumPy conventions).

导入 numpy 库(应该遵循标准的 NumPy 约定)。

python 复制代码
import numpy as np

2. 打印版本号

  • Print the version number of NumPy.

打印 NumPy 的版本号。

python 复制代码
print(np.__version__)

3. arange 函数

  • Use the arange function to generate 10 elements from 0 to 9 and store them in a variable named ndarray.

使用 arange 函数生成 10 个从 0 到 9 的元素,并将它们存储在名为 ndarray 的变量中。

python 复制代码
ndarray = np.arange(10)
print(ndarray)

4. array函数

  • Utilize the array function to convert data in Python list format into an equivalent ndarray named ndarray1.

利用array函数将 Python 列表格式的数据转换为名为 ndarray1 的等效 ndarray。

python 复制代码
ndarray1 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
print(ndarray1)

5. reshape函数

  • Reshape the ndarray and the ndarray1 into a 2-row by 5-column array.

将 ndarray 和 ndarray1 改造成 2 行 x 5 列数组。

python 复制代码
ndarray = ndarray.reshape(2, 5)
ndarray1 = ndarray1.reshape(2, 5)
print(ndarray)
print(ndarray1)

6. 矩阵点乘( 逐元素相乘)

  • Calculate the elementwise product of ndarray and ndarray1 using the * operator, and print the result

使用 * 运算符计算 ndarray 和 ndarray1 的元素乘积,并打印结果

python 复制代码
result = ndarray * ndarray1
print(result)

7. 矩阵乘法

  • Calculate the matrix product of ndarray and ndarray1 using the @ operator, and print the result. You need to use the T attribute to perform a transpose operation on ndarray1.

使用 @ 运算符计算 ndarray 和 ndarray1 的矩阵乘积,并打印结果。需要使用 T 属性在 ndarray1 上执行转置操作。

python 复制代码
result1 = ndarray @ ndarray1.T
print(result1)
相关推荐
人工智能培训5 小时前
数字孪生应用于特种设备领域的技术难点
人工智能·机器学习·语言模型·数字孪生·大模型幻觉·数字孪生应用
慧一居士5 小时前
OpenAI 和OpenApi 区别对比和关系
人工智能
资讯雷达5 小时前
2026 年,GEO 优化如何选?风信子传媒:以“内容生态+智能分发”重塑品牌 AI 认知
大数据·人工智能·传媒
张祥6422889045 小时前
误差理论与测量平差基础笔记七
线性代数·机器学习·numpy
中科天工5 小时前
当智能包装行业迎来新机遇,如何驾驭发展趋势?
大数据·人工智能·智能
BBTSOH159015160445 小时前
VR每日热点简报2026.1.23
人工智能·vr·人形机器人·动作捕捉·机械手·遥操作·数据手套
快降重科研小助手6 小时前
文科论述深度改写|挑战哲学论述文,“快降重”如何应对思辨文本?
人工智能·经验分享·aigc·ai写作·降重·降ai率
wan9zhixin6 小时前
2026年1月变电设备六氟化硫泄漏检测仪品牌推荐
大数据·网络·人工智能
bst@微胖子6 小时前
LlamaIndex之Workflow工作流案例
人工智能·机器学习
APIshop6 小时前
Java获取item_get-获得某书商品详情接口
java·开发语言·python