Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import numpy as np
  2. ...
  3. shape = np.shape((6, 6)) #This will be some pre-determined size
  4. sigma = np.diag(S) #diagonalise the matrix - this works
  5. my_sigma = sigma.resize(shape) #Resize the matrix and fill with zeros - returns "None" - why?
  6.  
  7. [x x x]
  8.  
  9. [x 0 0]
  10. [0 x 0]
  11. [0 0 x]
  12. [0 0 0]
  13. [0 0 0]
  14. [0 0 0] - or some similar size, but the diagonal elements are important.
  15.  
  16. import numpy as np
  17. ...
  18. shape = (6, 6) #This will be some pre-determined size
  19. sigma = np.diag(S) #diagonalise the matrix - this works
  20. sigma.resize(shape) #Resize the matrix and fill with zeros
  21.  
  22. # This assumes that you have a 2-dimensional array
  23. zeros = np.zeros(shape, dtype=np.int32)
  24. zeros[:sigma.shape[0], :sigma.shape[1]] = sigma
  25.  
  26. import numpy as np
  27.  
  28. A = np.array([1, 2, 3])
  29.  
  30. N = A.size
  31. B = np.pad(np.diag(A), ((0,N),(0,0)), mode='constant')
  32.  
  33. [[1 0 0]
  34. [0 2 0]
  35. [0 0 3]
  36. [0 0 0]
  37. [0 0 0]
  38. [0 0 0]]
  39.  
  40. bigger_sigma = np.zeros(shape, dtype=sigma.dtype)
  41. diag_ij = np.diag_indices_from(sigma)
  42. bigger_sigma[diag_ij] = sigma[diag_ij]
  43.  
  44. a = [1, 2, 3]
  45. b = []
  46. for i in range(6):
  47. b.append((([0] * i) + a[i:i+1] + ([0] * (len(a) - 1 - i)))[:len(a)])
  48.  
  49. [[1, 0, 0], [0, 2, 0], [0, 0, 3], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
  50.  
  51. S= np.ones((3))
  52. print (S)
  53. # [ 1. 1. 1.]
  54. d= np.diag(S)
  55. print(d)
  56. """
  57. [[ 1. 0. 0.]
  58. [ 0. 1. 0.]
  59. [ 0. 0. 1.]]
  60.  
  61. """
  62.  
  63. np.resize(d,(6,3))
  64. """
  65. adds a repeating value
  66. array([[ 1., 0., 0.],
  67. [ 0., 1., 0.],
  68. [ 0., 0., 1.],
  69. [ 1., 0., 0.],
  70. [ 0., 1., 0.],
  71. [ 0., 0., 1.]])
  72. """
  73.  
  74. d.resize((6,3),refcheck=False)
  75. print(d)
  76. """
  77. [[ 1. 0. 0.]
  78. [ 0. 1. 0.]
  79. [ 0. 0. 1.]
  80. [ 0. 0. 0.]
  81. [ 0. 0. 0.]
  82. [ 0. 0. 0.]]
  83. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement