1. 使用列表(List):
```python
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
person1 = Person("John", 25)
person2 = Person("Alice", 30)
persons = [person1, person2] 创建包含对象的列表
2. 使用NumPy库:
```python
import numpy as np
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
point1 = Point(2, 3)
point2 = Point(4, 5)
points = np.array([point1, point2]) 创建包含对象的NumPy数组
3. 使用第三方库,如Pandas:
```python
import pandas as pd
class Car:
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
car1 = Car("Toyota", "Corolla", 2020)
car2 = Car("Honda", "Civic", 2019)
cars = pd.DataFrame([car1.__dict__, car2.__dict__]) 使用Pandas创建包含对象的DataFrame
以上是定义对象数组的一些常见方法。您可以根据需要选择最适合您需求的方法