【深度学习实验】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)
相关推荐
AllData公司负责人1 小时前
AI大模型数据开发底座系列说明书,AllData集成Chat2DB开源项目建设AI 数据库分析底座,涵盖AI 洞察/对话SQL/智能视图!
数据库·人工智能·sql·开源·ai 洞察·对话sql
泯泷3 小时前
让 Agent 分清“马上办、等一等、顺手办”
人工智能·llm·agent
鲜于言悠9054 小时前
Claude Fable 5.2 登场,专治复杂推理与长任务
人工智能
大可不必了4 小时前
03 函数定义和调用
开发语言·python
联犀4 小时前
如何工程化降低语音交互AI设备的延迟(小智ai,芙崽这样的ai设备)
人工智能
杉岩数据5 小时前
杉岩数据董事长陈坚:从数据存储到行业智能——杉岩的AI时代战略布局
人工智能
冬奇Lab5 小时前
Loop 工程到底是高深的新技术,还是炒冷饭?用训练一个识别狗的模型讲明白
人工智能
冬奇Lab5 小时前
一天一个开源项目(第260篇):Plannotator —— 给 AI 编码 Agent 配一块「可批注的审阅台」,计划和代码改动都能在浏览器里逐条批示
人工智能·开源·claude
泯泷5 小时前
语音,正在成为 AI Agent 最自然的接口
人工智能·llm·agent
承渊政道5 小时前
【Python编程—从入门到实践】(记分与闯关:用Python+Pygame,打造越战越精彩的太空大战!)
开发语言·python·pycharm·游戏程序·pygame