Python: list vs. np.array: switching to use certain attributes -
i know, there plenty of threads list vs. array i've got different problem.
using python, find myself converting between np.array , list quite want use attributes like
remove, append, extend, sort, index, … lists
and on other hand modify content things like
*, /, +, -, np.exp(), np.sqrt(), … works arrays.
it must pretty messy switch between data types list(array) , np.asarray(list), assume. can't think of proper solution. don't want write loop every time want find , remove array.
any suggestions?
a numpy array:
>>> a=np.array([1,4,9,2,7])
delete:
>>> a=np.delete(a, [2,3]) >>> array([1, 4, 7])
append:
>>> a=np.append(a, [5,0]) >>> array([1, 4, 7, 5, 0])
sort:
>>> np.sort(a) array([0, 1, 4, 5, 7])
index:
>>> array([1, 4, 7, 5, 0]) >>> np.where(a==7) (array([2]),)
Comments
Post a Comment