In Java, we make an array of objects with a fixed size as follows
ArrayClass array_of_objects[]=new ArrayClass[10];
but how can I make a list of objects in python with a fixed size?
Create an empty list of size 5
lst = [None] * 5
use numpy
like below:
import numpy as np
size = 2
np.array([None]*size, dtype=object)
Output:
array([None, None], dtype=object)
you can use this like below:
arr = np.array([None]*2, dtype=object)
arr[0] = 1
arr[1] = 'str'
Output:
array([1, 'str'], dtype=object)