Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving list in a list
#3
measurements is return a NumPy Array
>>> import numpy as np
>>>
>>> n1 = np.array([0, 1])
>>> n1
array([0, 1])
>>> type(n1)
<class 'numpy.ndarray'>
So will work like a normal Python list,but you can convert.
>>> import numpy as np
>>> 
>>> n1 = np.array([0, 1])
>>> n2 = np.array([1, 2])
>>> lst = []
>>> # add list 
>>> lst.append(list(n1))
>>> lst.append(list(n2))
>>> lst
[[0, 1], [1, 2]]
On a finish list.
>>> import numpy as np
>>> 
>>> n1 = np.array([0, 1])
>>> n2 = np.array([1, 2])
>>> lst = []
>>> lst.append(n1)
>>> lst.append(n2)
>>> lst
[array([0, 1]), array([1, 2])]
>>> 
>>> new_lst = [list(i) for i in lst]
>>> new_lst
[[0, 1], [1, 2]] 
If it's a NumPy Array with serval item use .tolist.
>>> import numpy as np
>>> 
>>> m = np.array([[0,1], [2,3]])
>>> m
array([[0, 1],
       [2, 3]])
>>> m.tolist()
[[0, 1], [2, 3]]
quest_ likes this post
Reply


Messages In This Thread
Saving list in a list - by quest_ - Mar-08-2021, 01:44 PM
RE: Saving list in a list - by Larz60+ - Mar-08-2021, 02:09 PM
RE: Saving list in a list - by snippsat - Mar-08-2021, 02:41 PM
RE: Saving list in a list - by quest_ - Mar-10-2021, 09:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 284 Yesterday, 11:32 AM
Last Post: mmhmjanssen
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,258 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,602 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 953 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,903 Oct-26-2022, 04:03 PM
Last Post: deanhystad
Question Keyword to build list from list of objects? pfdjhfuys 3 1,621 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  Split a number to list and list sum must be number sunny9495 5 2,352 Apr-28-2022, 09:32 AM
Last Post: Dexty
  How to check if a list is in another list finndude 4 1,875 Jan-17-2022, 05:04 PM
Last Post: bowlofred
  Different out when using conda list and pip list Led_Zeppelin 1 4,104 Jan-14-2022, 09:30 PM
Last Post: snippsat
  Use one list as search key for another list with sublist of list jc4d 4 2,203 Jan-11-2022, 12:10 PM
Last Post: jc4d

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020