How to separate this two elements from a single array?
[array([0.1, 5.6])] # numpy array
target:
[array([0.1]), array([5.6])]
CodePudding user response:
You can use map():
map(lambda x: [x], your_array)
Example:
source = ["a", "b", "c"]
target = map(lambda x: [x], source)
print(list(target))
# OUTPUT:
# [["a"], ["b"], ["c"]]
CodePudding user response:
I would appreciate if you elaborate your goal. Coming to your question,you could easily do similar to the following using numpy.
import numpy as np
list_data = [1,2,3,4,5,6,7]
array = np.array(list_data)
new_array = np.array(array[:x], array[x:]) where x is a position.
CodePudding user response:
If you are using python arrays for some reasons instead of the build-in lists, you should do this:
from array import array
arr = [array('d', [0.1, 5.6])]
spl = [array('d', a) for a in arr]
However, I would recommend a simple list for your task:
lis = [0.1, 5.6]
sp = [[dbl] for dbl in lis]
Then you do not need to import a module.