Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- ...
- shape = np.shape((6, 6)) #This will be some pre-determined size
- sigma = np.diag(S) #diagonalise the matrix - this works
- my_sigma = sigma.resize(shape) #Resize the matrix and fill with zeros - returns "None" - why?
- [x x x]
- [x 0 0]
- [0 x 0]
- [0 0 x]
- [0 0 0]
- [0 0 0]
- [0 0 0] - or some similar size, but the diagonal elements are important.
- import numpy as np
- ...
- shape = (6, 6) #This will be some pre-determined size
- sigma = np.diag(S) #diagonalise the matrix - this works
- sigma.resize(shape) #Resize the matrix and fill with zeros
- # This assumes that you have a 2-dimensional array
- zeros = np.zeros(shape, dtype=np.int32)
- zeros[:sigma.shape[0], :sigma.shape[1]] = sigma
- import numpy as np
- A = np.array([1, 2, 3])
- N = A.size
- B = np.pad(np.diag(A), ((0,N),(0,0)), mode='constant')
- [[1 0 0]
- [0 2 0]
- [0 0 3]
- [0 0 0]
- [0 0 0]
- [0 0 0]]
- bigger_sigma = np.zeros(shape, dtype=sigma.dtype)
- diag_ij = np.diag_indices_from(sigma)
- bigger_sigma[diag_ij] = sigma[diag_ij]
- a = [1, 2, 3]
- b = []
- for i in range(6):
- b.append((([0] * i) + a[i:i+1] + ([0] * (len(a) - 1 - i)))[:len(a)])
- [[1, 0, 0], [0, 2, 0], [0, 0, 3], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
- S= np.ones((3))
- print (S)
- # [ 1. 1. 1.]
- d= np.diag(S)
- print(d)
- """
- [[ 1. 0. 0.]
- [ 0. 1. 0.]
- [ 0. 0. 1.]]
- """
- np.resize(d,(6,3))
- """
- adds a repeating value
- array([[ 1., 0., 0.],
- [ 0., 1., 0.],
- [ 0., 0., 1.],
- [ 1., 0., 0.],
- [ 0., 1., 0.],
- [ 0., 0., 1.]])
- """
- d.resize((6,3),refcheck=False)
- print(d)
- """
- [[ 1. 0. 0.]
- [ 0. 1. 0.]
- [ 0. 0. 1.]
- [ 0. 0. 0.]
- [ 0. 0. 0.]
- [ 0. 0. 0.]]
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement