机器学习笔记1————机器学习(科学计算库numpy)

​​​​​​Numpy(Numerical Python)是一个开源的Python科学计算库,用于快速处理任意维度的数组

Numpy支持常见的数组和矩阵操作。对于同样的数值计算任务,使用Numpy比直接使用Python要简洁的多。

Numpy使用ndarray对象来处理多维数组,该对象是一个快速而灵活的大数据容器。

1.ndarray

import numpy as np

# 创建ndarray
score = np.array(
[[80, 89, 86, 67, 79],
[78, 97, 89, 67, 81],
[90, 94, 78, 67, 74],
[91, 91, 90, 67, 69],
[76, 87, 75, 67, 86],
[70, 79, 84, 67, 84],
[94, 92, 93, 67, 64],
[86, 85, 83, 67, 80]])

score

#输出:
array([[80, 89, 86, 67, 79],
       [78, 97, 89, 67, 81],
       [90, 94, 78, 67, 74],
       [91, 91, 90, 67, 69],
       [76, 87, 75, 67, 86],
       [70, 79, 84, 67, 84],
       [94, 92, 93, 67, 64],
       [86, 85, 83, 67, 80]])

2.运算时间对比

3.ndarray属性

 4.ndarray形状

# 创建不同形状的数组
a = np.array([[1,2,3],[4,5,6]])
b = np.array([1,2,3,4])
c = np.array([[[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]]])
a.shape
b.shape
c.shape

#输出
(2, 3)  # 二维数组
(4,)    # 一维数组
(2, 2, 3) # 三维数组

5.ndarray类型

6.ndarray基本操作

  • np.ones(shape, dtype)
  • np.ones_like(a, dtype)
  • np.zeros(shape, dtype)
  • np.zeros_like(a, dtype) 
  • np.array(object, dtype)

  • np.asarray(a, dtype)

  • np.linspace (start, stop, num, endpoint)

  • np.arange(start,stop, step, dtype)

  • np.logspace(start,stop, num)

  • np.random.randn(d0, d1, …, dn)
  • np.random.normal(loc=0.0scale=1.0size=None)
  • np.random.standard_normal(size=None)
  • np.random.rand(d0d1...dn)
  • np.random.uniform(low=0.0high=1.0size=None)
  • np.random.randint(lowhigh=Nonesize=Nonedtype='l')
  • ndarray.reshape(shape, order)

  • ndarray.resize(new_shape)

  • ndarray.T

  • ndarray.astype(type)

  • ndarray.tostring([order])

  • ndarray.tobytes([order])

  • np.unique()

 7.ndarray的运算

  • < > = 
  • np.all()
  • np.any()
  • np.where

  • np.max()
  • np.min()
  • np.median()
  • np.mean()
  • np.std()
  • np.var()
  • np.argmax(axis=) — 最大元素对应的下标
  • np.argmin(axis=) — 最小元素对应的下标
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ThinkinDifferent

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值