'How to add square brackets to values in numpy array
Below is my working code:
import numpy as np
test = [{"test":np.array([["value1,value1"],["value2,value2"]])},{"names":
["test1","test2"]}]
q = ["value3,value3"]
v = ["test3"]
for p in test:
for item,value in p.items():
if str(item).startswith("test"):
p["test"] = np.append(p["test"],np.array([q]))
if str(item).startswith("names"):
for r in v:
p["names"].append(r)
I need output as following:
[{'test': array([['value1,value1'], ['value2,value2'], ['value3', 'value3']],
dtype='<U13')},
{'names': ['test1', 'test2', 'test3']}]
but currently im getting like below:
[{'test': array(['value1,value1', 'value2,value2', 'value3', 'value3'], dtype='<U13')},
{'names': ['test1', 'test2', 'test3']}]
Where am I doing silly mistake ? Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
