numpy数组坐标轴问题如何解决 您所在的位置:网站首页 以太坊能达到多少 numpy数组坐标轴问题如何解决

numpy数组坐标轴问题如何解决

2023-03-13 12:40| 来源: 网络整理| 查看: 265

numpy数组坐标轴问题如何解决 发布时间:2023-03-13 10:55:18 来源:亿速云 阅读:88 作者:iii 栏目:开发技术

本篇内容介绍了“numpy数组坐标轴问题如何解决”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

首先我们讨论一维的情况,代码如下:

import numpy as np class Debug:     def __init__(self):         self.array1 = np.array([0, 1, 2])         self.array2 = np.array([[0], [1], [2]])     def mainProgram(self):         print("The value of array1 is: ")         print(self.array1)         print("The shape of array1 is: ")         print(self.array1.shape)         print("The value of array2 is: ")         print(self.array2)         print("The shape of array2 is: ")         print(self.array2.shape) if __name__ == '__main__':     main = Debug()     main.mainProgram() """ The value of array1 is:  [0 1 2] The shape of array1 is:  (3,) The value of array2 is:  [[0]  [1]  [2]] The shape of array2 is:  (3, 1) """

从上面的结果我们可以看到,一维横数组沿着横向排列,我们可以认定为x轴向,它的数组大小为(3,),一维列数组沿着纵向排列,我们可以认为是y轴方向,它的大小为(3, 1),我们可以从左向右,看出第二个参数代表的是横向上的参数个数,第一个参数代表的是纵向上的参数个数,因此我们可以将横向数组的大小(3,)理解为(,3)更为合适。

接下来我们研究一下二维数组,哪个参数对应的是横坐标,哪个参数对应的是纵坐标。代码如下:

import numpy as np class Debug:     def __init__(self):         self.array1 = np.ones((2, 3))         self.array2 = np.ones((3, 2))     def mainProgram(self):         print("The value of array1 is: ")         print(self.array1)          print("The shape of array1 is: ")         print(self.array1.shape)         print("The value of array2 is: ")         print(self.array2)         print("The shape of array2 is: ")         print(self.array2.shape) if __name__ == '__main__':     main = Debug()     main.mainProgram() """ The value of array1 is:  [[1. 1. 1.]  [1. 1. 1.]] The shape of array1 is:  (2, 3) The value of array2 is:  [[1. 1.]  [1. 1.]  [1. 1.]] The shape of array2 is:  (3, 2) """

从上面的结果我们可以看出,从左向右,第一个参数代表的是(row), 第二个参数代表的是列(column)。我们知道numpy中默认的是笛卡尔坐标系,所以横向为x,纵向为y,具体的请看坐标系(超链接点击跳转查看)。所以对self.array1来说,定义时输入的数组大小的(2, 3)代表沿着x轴拥有3个值,沿着y轴拥有2个值。对比上述得到的结果与我们在一维情况中推断得到的结果,证明我们的理解是正确的。

接着我们讨论三维的情况:代码如下:

import numpy as np class Debug:     def __init__(self):         self.array1 = np.ones((2, 3, 4))     def mainProgram(self):         print("The value of array1 is: ")         print(self.array1)         print("The shape of array1 is: ")         print(self.array1.shape) if __name__ == '__main__':     main = Debug()     main.mainProgram() """ The value of array1 is:  [[[1. 1. 1. 1.]   [1. 1. 1. 1.]   [1. 1. 1. 1.]]  [[1. 1. 1. 1.]   [1. 1. 1. 1.]   [1. 1. 1. 1.]]] The shape of array1 is:  (2, 3, 4) """

不难发现,沿着x轴方向拥有4个值,沿着y轴方向拥有3个值,沿着z轴方向拥有2个值。

“numpy数组坐标轴问题如何解决”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读: Python Numpy中ndarray的常见操作实例分析 Python数据分析numpy数组的创建方式有哪些

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:[email protected]进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

numpy 上一篇新闻:SpringCloud Ribbon负载均衡使用策略是什么 下一篇新闻:微信小程序怎么使用Promise对wx.request()封装 猜你喜欢 python如何检查对象的内存占用情况 java如何使用substring()方法反转字符 如何使用python实现列表反转 linux如何使用rm命令删除目录 java如何使用Byte数组反转字符 java如何通过交换实现字符反转 java如何使用String charAt方法反转字符 python如何将元素进行重复 python如何判断字符串是不是回文串 js如何通过字符获取位置或通过位置获取字符


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有