Issue
I have an list of arrays, I want to reshape each array in the list and then stack.
A sample below
C = np.array([[-127, -108, -290],
[-123, -83, -333],
[-126, -69, -354],
[-146, -211, -241],
[-151, -209, -253],
[-157, -200, -254]])
D = np.array([[-129, -146, -231],
[-127, -148, -238],
[-132, -157, -231],
[ -93, -355, -112],
[ -95, -325, -137],
[ -99, -282, -163]])
E = np.array(([[-141, -133, -200],
[-132, -123, -202],
[-119, -117, -204],
[-107, -210, -228],
[-101, -194, -243],
[-105, -175, -244]]))
ArrayList = (C,D,E)
to reshape an individual array I do the following
newArray = ArrayList[0].reshape(1,-1)
and produces the desired result
array([[-127, -108, -290, -123, -83, -333, -126, -69, -354, -146, -211,
-241, -151, -209, -253, -157, -200, -254]])
I tried writing a for loop to go through each item
newArray = []
for i in ArrayList:
i.reshape(1,-1)
newArray.append(i)
But I got the same product as what I started with. The desired output is shown below
(array([[-127, -108, -290, -123, -83, -333, -126, -69, -354, -146, -211,
-241, -151, -209, -253, -157, -200, -254]]),
array([[-129, -146, -231, -127, -148, -238, -132, -157, -231, -93, -355,
-112, -95, -325, -137, -99, -282, -163]]),
array([[-141, -133, -200, -132, -123, -202, -119, -117, -204, -107, -210,
-228, -101, -194, -243, -105, -175, -244]]))
Any help appreciated.
Solution
I think you just need to do this:
newArray = []
for i in ArrayList:
j = i.reshape(1,-1)
newArray.append(j)
print(newArray)
Output:
[array([[-127, -108, -290, -123, -83, -333, -126, -69, -354, -146, -211,
-241, -151, -209, -253, -157, -200, -254]]),
array([[-129, -146, -231, -127, -148, -238, -132, -157, -231, -93, -355,
-112, -95, -325, -137, -99, -282, -163]]),
array([[-141, -133, -200, -132, -123, -202, -119, -117, -204, -107, -210,
-228, -101, -194, -243, -105, -175, -244]])]
Answered By - constantstranger
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.