Closed Sheila-nk closed 1 year ago
The current implementation works only for 1-dim numpy arrays:
In [1]: s = "array([ 0, 1, 2, ..., 999997, 999998, 999999])" In [2]: eval(s, {'array': np.array}) Out[2]: array([0, 1, 2, Ellipsis, 999997, 999998, 999999], dtype=object)
but produces a ValueError for multi-dim arrays as ellipses abbreviate the rows:
ValueError
In [19]: s = """array([[0. , 0. , 0. , ..., 0. , 0. , ...: 0. ], ...: [0. , 0.03333333, 0. , ..., 0. , 0. , ...: 0. ], ...: [0. , 0. , 0.06666667, ..., 0. , 0. , ...: 0. ], ...: ..., ...: [0. , 0. , 0. , ..., 1. , 0. , ...: 0. ], ...: [0. , 0. , 0. , ..., 0. , 1.03333333, ...: 0. ], ...: [0. , 0. , 0. , ..., 0. , 0. , ...: 1.06666667]])""" In [20]: eval(s, {'array': np.array}) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[20], line 1 ----> 1 eval(s, {'array': np.array}) File <string>:1 ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (7,) + inhomogeneous part.
The current implementation works only for 1-dim numpy arrays:
but produces a
ValueError
for multi-dim arrays as ellipses abbreviate the rows: