How to append YTArray in a for loop as YTArray object has no attribute append?

70 Views Asked by At
yt_arr = YTArray([])
for i in range(10):
   yt_arr.append(i)

This particular type of code returns an error saying that YTArray has no attribute append. So how do I append values in the array?

1

There are 1 best solutions below

0
Sabito stands with Ukraine On

You can append the contents to a list and later convert it to a YTArray object.

arr = []
yt_arr = YTArray([])
for i in range(10):
    arr.append(i) 
yt_arr = YTArray(arr,'cm') # add your symbolic reference here