the following are numpy arrays:
x = [1 0]
[0 1]
y = [1 2]
[3 4]
what numpy function would put both of these arrays in to the following 4x4 matrix:
p = [x x]
[y y]
so it would like this:
p = [1 0 1 0]
[0 1 0 1]
[1 2 1 2]
[3 4 3 4]
Here is the answer...
CODE:
import numpy as np
x = np.array([[1, 0],[0,1]])
y = np.array([[1, 2],[3,4]])
print(type(x))
print("X =",x)
print(type(y))
print("Y =",y)
p=np.column_stack([[x,x],[y,y]]) #here we arrange column wise
k=np.column_stack(p) #again arrange in column wise
m=np.asmatrix(k) #convert them to matrix
print("\nMatrix is")
print(m) #print matrix
print(m.shape,type(m)) #print its shape and type
CODE and OUTPUT:
If you have any doubts please COMMENT....
If you understand the answer please give THUMBS UP..
Get Answers For Free
Most questions answered within 1 hours.