美文网首页
【Python | NumPy】基础

【Python | NumPy】基础

作者: 盐果儿 | 来源:发表于2022-08-12 05:20 被阅读0次

1. 创建一个NumPy数组

x = np.array([list])

2. 访问数组属性

x.ndim # the number of dimensions of the array

x.size # the total number of elements of the array

x.shape # returns a tuple of integers that indicate the number of elements stored along each dimension of the array.

x.dtype # type of the ndarray

3. 基本数组操作

# 为NumPy数组添加元素4

x = np.append(x, 4)

# 删除NumPy数组中第一个元素

x = np.delete(x, 0)

# 将NumPy数组中元素排序

x = np.sort(x)

# 创建一个数组(注意"arange"只有一个"r")

x = np.arange(2, 10, 3)

4. Changing the shape

# 将数组变为3行,2列的二维数组

x = np.reshape(3, 2)

# 将数组变为一维数组

x = np.reshape(7)

5. Indexing and slicing

NumPy arrays can be indexed and sliced the same way that Python lists are.

import numpy as np

x = np.arange(1, 10)

print(x)

print(x[0:2])

print(x[5:])

print(x[:2])

print(x[-3:])

#打印特定条件下的数组

print(x[x<4])

print(x[(x > 5) & (x%2 == 0)])

6. 数组计算

# The sum of all elements

x.sum()

# Get the smallest / largest element

x.min()

x.max()

# Multiply all elements by 2

y = x * 2

7. Statistics

print(np.mean(x))

print(np.median(x))

print(np.var(x))

print(np.std(x))

相关文章

  • Numpy | 基础操作(矩阵)

    NumPy 基础操作 什么是 NumPy NumPy是Python中科学计算的基础包。它是一个Python库,提供...

  • Numpy

    NumPy是Numeric Python的简称 NumPy是Python科学计算的基础工具包 NumPy是Pyth...

  • Python之Numpy使用教程

    1.NumPy概述 NumPy(Numerical Python)是用Python进行科学计算的基础软件包。包含以...

  • numpy

    Numpy概述 NumPy(Numerical Python的简称)是Python数值计算最重要的基础包。大多数提...

  • 2020-07-29--数据分析-numpy

    Numpy概述 NumPy(Numerical Python的简称)是Python数值计算最重要的基础包。大多数提...

  • Python——ndarray多维数组对象介绍

    1.Numpy库介绍: Numpy是Numercial Python的简称,是一个开源的Python科学计算基础库...

  • 2019-09-11丨创作101第一季丨第15天丨学习笔记

    实践过程:NumPy数组对象基础(一)——Python示例 NumPy作为Python的第三方库,是学习数据分析、...

  • 2018-07-02Python数组

    Python基础学习-Python中最常见括号()、[]、{}的区别 NumPy数组(1、数组初探) Python...

  • Numpy随笔

    Numpy NumPy是SciPy、Pandas等数据处理或科学计算库的基础 NumPy是一个开源的Python科...

  • 利用Python进行数据分析-NumPy基础

    本文出自<利用Python进行数据分析第2版>侵删 NumPy NumPy是Python数值计算最重要的基础包,可...

网友评论

      本文标题:【Python | NumPy】基础

      本文链接:https://www.haomeiwen.com/subject/ashxgrtx.html