Defining advanced matrix operations
This book takes you through all sorts of interesting matrix operations, but you use
some of them commonly, which is why they appear in this chapter. When working
with arrays, you sometimes get data in a shape that doesn’t work with the algo-
rithm. Fortunately,
numpy
comes with a special
reshape
function that lets you put
the data into any shape needed. In fact, you can use it to reshape a vector into a
matrix, as shown in the following code:
changeIt = np.array([1,2,3,4,5,6,7,8])
changeIt
array([1, 2, 3, 4, 5, 6, 7, 8])
changeIt.reshape(2,4)
array([[1, 2, 3, 4],
[5, 6, 7, 8]])
CHAPTER 5
Do'stlaringiz bilan baham: |