harold
harold

Reputation: 35

array transform in python

I am working with python, and I Got an array which looks like (750 ,), and it is a matrix with 750 rows and 1 column. but I would like to make it look like (750, 1). to be specific, I would like to do a transform : (750, )--->(750,1). any advice ?

Upvotes: 0

Views: 9322

Answers (1)

bobolafrite
bobolafrite

Reputation: 100

First let's create a (750,) array :

import numpy as np
test_array = np.array(range(750))

test_array.shape 
# Returns (750,)

You can create a new array with the shape you want with the np.ndarray.reshape() method :

new_array = test_array.reshape([750,1])

It is equivalent to

new_array = np.reshape(test_array,[750,1])

Upvotes: 1

Related Questions