1. 使用 `len()` 函数:
```python
my_list = [1, 2, 3, 4, 5]
length = len(my_list)
print("数组元素个数为:", length)
2. 使用 `count()` 方法(适用于列表和元组):
```python
my_tuple = (1, 2, 3, 2, 4, 2)
count_2 = my_tuple.count(2)
print("元组中2的个数为:", count_2)
3. 使用 `numpy` 库的 `size` 属性(适用于 `numpy` 数组):
```python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
count = arr.size
print("数组元素个数为:", count)
以上方法适用于一维数组。对于更复杂的数据结构,如二维数组,可以使用 `numpy` 的 `shape` 属性来获取数组的维度信息。