Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

NumPy 入门


NumPy 的安装

如果您已经在系统上安装了PythonPIP,那么安装 NumPy 非常简单。

使用以下命令安装它

C:\Users\您的用户名>pip install numpy

如果此命令失败,则使用已安装 NumPy 的 Python 发行版,例如 Anaconda、Spyder 等。


导入 NumPy

安装 NumPy 后,通过添加 import 关键字将其导入您的应用程序

import numpy

现在 NumPy 已导入并可以使用。

示例

import numpy

arr = numpy.array([1, 2, 3, 4, 5])

print(arr)
自己试一试 »

将 NumPy 作为 np

NumPy 通常在 np 别名下导入。

别名:在 Python 中,别名是引用同一事物的替代名称。

在导入时使用 as 关键字创建别名

import numpy as np

现在,NumPy 包可以称为 np 而不是 numpy

示例

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr)
自己试一试 »

检查 NumPy 版本

版本字符串存储在 __version__ 属性下。

示例

import numpy as np

print(np.__version__)
自己试一试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.