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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -