Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 2.41 KB

File metadata and controls

48 lines (37 loc) · 2.41 KB

Numpy

Let's do it

import numpy as np
import numpy as np

python_list = [[[1, 2, 3, 4], [4, 5, 6, 7]], [
    [1, 2, 3, 4], [4, 5, 6, 7]], [[1, 2, 3, 4], [4, 5, 6, 7]]]
np.array(python_list).shape

arr = np.array(python_list)
print(arr)
>>> array([[[1, 2, 3, 4],
            [4, 5, 6, 7]],

           [[1, 2, 3, 4],
            [4, 5, 6, 7]],

           [[1, 2, 3, 4],
            [4, 5, 6, 7]]])

print(arr[:, 1, 2])
>>> array([6, 6, 6])

Useful stuff

  • np.empty # Return a new array of given shape and type, without initializing entries.
  • np.zeros # Return a new array of given shape and type, filled with zeros.
  • np.ones # Return a new array of given shape and type, filled with ones
  • np.nonzero # Return the indices of the elements that are non-zero.
  • np.eye # Return a 2-D array with ones on the diagonal and zeros elsewhere.
  • np.arange # Return evenly spaced values within a given interval.
  • np.reshape # Gives a new shape to an array without changing its data
  • np.random.random # Return random floats
  • np.identity # Return the identity array
  • np.linspace # Return evenly spaced numbers over a specified interval
  • np.diag # Extract a diagonal or construct a diagonal array
  • np.pad
  • np.unravel_index # Converts a flat index or array of flat indices into a tuple of coordinate arrays
  • np.
  • np.