简体   繁体   English

如何获取numpy.array的维数

[英]How to retrieve the dimensions of a numpy.array

I am very new to learning python and I am trying to scale a matrix in np. array 我对学习python非常陌生,并且尝试在np. array缩放矩阵np. array np. array nxm . np. array nxm the question is, if a matrix in the np.array is given as input and I don't know how big the range the matrix, how I can initialize the size m ? 问题是,如果给出np.array的矩阵作为输入,但我不知道该矩阵的范围有多大,如何初始化大小m Are there certain features in Python that can be used for this? Python中是否有某些features可用于此目的?

import numpy as np
def scaleArray(arr: np.array);
    ##how ??

arrayB = np.array([[1,2,4],
                   [3,4,5],
                   [2,1,0],
                   [0,1,0]])
scaleArray(b)

this arrayB is just for example 这个arrayB只是举例

Expected output : 预期产量:

3

arr.shape is what you are looking for, it gives you the dimensions of the nD array. arr.shape是您想要的,它为您提供了nD数组的尺寸。

In your case, you want arr.shape[1] 您需要的是arr.shape[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM