• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
1fonly
博客园    首页    新随笔    联系   管理    订阅  订阅
机器学习随笔

Python基础

1.格式化输出:

使用f-string

print(f"str{vvariable}") 花括号( curly braces )中可以为式子

The content between the curly braces is evaluated when producing the output.

Numpy相关

https://www.runoob.com/numpy/numpy-ndarray-object.html

1.np.array 与np.ndarray的区别

即ndarray是类,而array是函数,array构建的是一个ndarray的对象,使用默认构造函数创建的ndarray对象的数组元素是随机值,而numpy提供了一系列的创建ndarray对象的函数,array()就是其中的一种;
https://blog.csdn.net/weixin_43708622/article/details/111138281


2.np.reshape 与np.resize的区别

在numpy模块中,我们经常会使用resize 和 reshape,在具体使用中,通常是使用resize改变数组的尺寸大小,使用reshape用来增加数组的维度。
Reshape
The previous example used reshape to shape the array.
a = np.arange(6).reshape(-1, 2)
This line of code first created a 1-D Vector of six elements. It then reshaped that vector into a 2-D array using the reshape command. This could have been written:
a = np.arange(6).reshape(3, 2)
To arrive at the same 3 row, 2 column array.
The -1 argument tells the routine to compute the number of rows given the size of the array and the number of columns.

属性 说明
ndarray.ndim 秩,即轴的数量或维度的数量
ndarray.shape 数组的维度,对于矩阵,n 行 m 列
ndarray.size 数组元素的总个数,相当于 .shape 中 n*m 的值
ndarray.dtype ndarray 对象的元素类型
ndarray.itemsize ndarray 对象中每个元素的大小,以字节为单位
ndarray.flags ndarray 对象的内存信息
ndarray.real ndarray元素的实部
ndarray.imag ndarray 元素的虚部
ndarray.data 包含实际数组元素的缓冲区,由于一般通过数组的索引获取元素,所以通常不需要使用这个属性。

3.注意区别np.array([[1, 3, 5, 7, 9]])与np.array([1, 3, 5, 7, 9])的区别
前者的shape为(1,5),后者为(5,)

matplotlib相关

https://www.runoob.com/matplotlib/matplotlib-tutorial.html

posted on 2023-06-15 13:48  ifonly  阅读(27)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3