Wednesday 4 January 2017

How to convert Python array_like Objects to Numpy Arrays?

In general, numerical data arranged in an array-like structure(example: lists and tuples.) in Python can be converted to arrays by the use of the array() function.

Example:
>>> x = np.array([2,3,1,0])
>>> x
array([2, 3, 1, 0])

>>> x = np.array([[1,2.0],[0,0],(1+1j,3.)])
>>> x
array([[ 1.+0.j,  2.+0.j],
       [ 0.+0.j,  0.+0.j],
       [ 1.+1.j,  3.+0.j]])



>>> x = np.array([[ 1.+0.j, 2.+0.j], [ 0.+0.j, 0.+0.j], [ 1.+1.j, 3.+0.j]])
>>> x
array([[ 1.+0.j,  2.+0.j],
       [ 0.+0.j,  0.+0.j],
       [ 1.+1.j,  3.+0.j]])