Reputation: 321
When I append elements to an empty list, it tends to overcomplicate.
I get:
A = array([[1],[1],...,[1]])
I want:
A = array([1,1...,1])
Upvotes: 2
Views: 3353
Reputation: 78
To avoid this when you're adding elements to the list, you can use extend
instead of append
Upvotes: 0
Reputation: 5714
you can try an inner loop to append to another list:
A = ([[1],[4],[5]])
b = []
for x in A:
for i in x:
b.append(i)
print(b)
output:
[1, 4, 5]
Upvotes: 0
Reputation: 18045
import numpy as np
A = np.array([[1], [1], [1]])
B = A.flatten()
Upvotes: 5