Up until now, we have connected the two data in the column direction using the following code.
Each row * column has data1 in the form of 2*32, data2 in the form of 5*32, and data3 in the form of 8*32.
For data1 and data2 only, I could do the following. (7*32 shape)
import numpy as np
# Verify index has been deleted
data1=np.loadtxt('210122-945 and 1200-del-stand-t-all.csv', delimiter=", ")
data2=np.loadtxt('210123-945 and 1200-del-stand-t-pre.csv', delimiter=", ")
data=np.append(data1,data2,axis=0)
print(data)
This time, when I connected more than three pieces of data with the following code, an error got caught in Axis=0. I'm aiming for the form of 15*32.
import numpy as np
# Verify index has been deleted
data1=np.loadtxt('210122-945 and 1200-del-stand-t-all.csv', delimiter=", ")
data2=np.loadtxt('210123-945 and 1200-del-stand-t-pre.csv', delimiter=", ")
data3=np.loadtxt('210124-945 and 1200-del-stand-t-pre.csv', delimiter=",")
data=np.append(data1,data2,data3,axis=0)
print(data)
How can I get there smoothly? Can't I use append in the first place?
python python3 numpy
This article will be helpful.
Combine the NumPy array ndarray (concatenate, stack, block, etc.)
How To Concatenate Arrays in NumPy?
numpy.append(arr,values,axis=None) can only specify two arrays, so
Parameters
You can use numpy.concatenate(a1,a2,...),axis=0,out=None) to concatenate.(It can be used in two situations)
Parameters
For the source of the question:
data=np.append(data1,data2,data3,axis=0)
You can do it if you use a list or a tuple like this:
data=np.concatenate([data1,data2,data3],axis=1)
or:
data=np.concatenate(data1,data2,data3),axis=1)
You can also do the same with numpy.hstack(tup), which eliminates the need to specify axis=
.
Parameters
containate
Same as this:
data=np.hstack([data1,data2,data3])
or:
data=np.hstack(data1,data2,data3))
Incidentally, if "coupling in the column direction" is a misunderstanding and actually "coupling in the row direction", the
axis=1
parameter in containate
should be axis=0
or
© 2024 OneMinuteCode. All rights reserved.