0
点赞
收藏
分享

微信扫一扫

numpy中的array相关重要属性

闲嫌咸贤 2022-04-21 阅读 171
pythonnumpy

目录

一、ndim属性

二、shape属性

三、size属性

四、dtype属性


一、ndim属性

输出array的维度

示例:


import numpy as np 
 
array = np.array([[1, 2, 3], [2, 3, 4]])
print(array)		#print the np.array
print(array.ndim)	#print the dimension of the np.array

>>>
[[1 2 3]
 [2 3 4]]
2

二、shape属性

输出array的形状

示例:

import numpy as np

array = np.array([[1, 2, 3], [2, 3, 4]])
print(array)  # print the np.array
print(array.shape)  # print the shape of the np.array

>>>
[[1 2 3]
 [2 3 4]]
(2, 3)

三、size属性

输出array中数据的个数

示例:

import numpy as np

array = np.array([[1, 2, 3], [2, 3, 4]])
print(array)  # print the np.array
print(array.size)  # print the size of the np.array

>>>
[[1 2 3]
 [2 3 4]]
6

四、dtype属性

输出array的数据类型

示例:

import numpy as np

array = np.array([[1, 2, 3], [2, 3, 4]])
print(array)  # print the np.array
print(array.dtype)  # print the data type of the np.array

>>>
[[1 2 3]
 [2 3 4]]
int32
举报

相关推荐

0 条评论