【深度学习实验】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)
相关推荐
刘海东刘海东3 分钟前
一条新的人工智能道路(刘海东)一、二、三章
人工智能
xyz_CDragon11 分钟前
从 RTL 到 GDSII:人与 AI 协作,用开源 EDA 工具链完成 SHA-256 芯片的 SoC 集成与签核全流程(附完整流程+代码)
人工智能·开源·芯片设计·开源 eda·caravel
咕咕AI学堂24 分钟前
检索引擎深度对比:Elasticsearch vs Milvus vs Redis 在 RAG 中的定位
人工智能
Java牛马29 分钟前
AI Agent 技术栈梳理(Skill / 蒸馏 / MCP / Harness)
人工智能·ai agent·蒸馏·skill·mcp·harness
IT_陈寒43 分钟前
Vue的computed属性把我坑惨了,原来我一直用错姿势
前端·人工智能·后端
千维百策6661 小时前
降低 AI 辅助开发摩擦的五种模式
人工智能
大鹏说大话1 小时前
从爬虫到决策引擎:大数据下自媒体如何用Python挖掘用户痛点
开发语言·爬虫·python
Niuguangshuo1 小时前
silero-vad:超轻量级开源 VAD 实践指南
开发语言·python
有脚就行1 小时前
第38篇-LLM-API网关进阶-流式代理与内容安全
人工智能
AI英德西牛仔1 小时前
从Excel乱象到批量交付:秘塔Excel与“AI导出鸭”PC版的底层重构逻辑
人工智能·重构·excel·deepseek·ai导出鸭