Python numpy.alen()
numpy.alen()函数用于返回输入数组的第一维的长度。
语法: numpy.alen(arr)
参数 :
arr : [array_like] 输入阵列。
返回 : [int]Arr的第一个维度的长度。
代码#1:
# Python program explaining
# alen() function
import numpy as geek
# input array(2 * 3)
in_arr = geek.array([[ 2, 0, 7], [ 0, 5, 9]])
print ("Input array : ", in_arr)
out_dim = geek.alen(in_arr)
print ("Length of the first dimension of arr: ", out_dim)
输出:
Input array : [[2, 0, 7], [0, 5, 9]]
Length of the first dimension of arr: 2
代码#2:
# Python program explaining
# alen() function
import numpy as geek
# input array(1 * 3*3)
in_arr = geek.arange(9).reshape(1, 3, 3)
print ("Input array : \n", in_arr)
out_dim = geek.alen(in_arr)
print ("Length of the first dimension of arr: ", out_dim)
输出:
Input array :
[[[0 1 2]
[3 4 5]
[6 7 8]]]
Length of the first dimension of arr: 1