# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # NumPy

# To work with NumPy you should import it

import numpy as np

# You can create NumPy array from python list

my_list = [1,2,3]

arr = np.array(my_list)

arr

# Or without temporary variable

arr = np.array([1, 2, 3])

arr

# ## arange
# Return evenly spaced values within a given interval.

np.arange(3)

np.arange(3.0)

np.arange(3,7)

np.arange(3,7,2)

# ## zeros
# Return a new array of given shape and type, filled with zeros.

np.zeros(5)

np.zeros((5,), dtype=np.int)

np.zeros((2, 1))

np.zeros((2,3))

# ## ones
# Return a new array of given shape and type, filled with ones.

np.ones(5)

np.ones((5,), dtype=np.int)

np.ones((2, 1))

np.ones((2,3))

# ## linspace
# Return evenly spaced numbers over a specified interval.

np.linspace(2.0, 3.0, num=5)

np.linspace(2.0, 3.0, num=5, endpoint=False)

np.linspace(2.0, 3.0, num=5, retstep=True)

# ## random.randint
# Return random integers from low (inclusive) to high (exclusive).

np.random.randint(2, size=10)

np.random.randint(1, size=10)

np.random.randint(5, size=(2, 4))

# ## random.normal
# Draw random samples from a normal (Gaussian) distribution.

np.random.normal(0, 0.1, 10)

# ## random.seed
# Seed the generator.

np.random.seed(101)
np.random.randint(2, size=5)

# The same

np.random.seed(101)
np.random.randint(2, size=5)

# ## max

arr = np.array(np.random.randint(10, size=10))

arr

arr.max()

# ## min

arr.min()

# ## mean

arr.mean()

# ## argmax

arr.argmax()

# ## reshape
# Gives a new shape to an array without changing its data.

arr.reshape((2, 5))

arr.reshape((1, 10))

arr.reshape((10, 1))

arr.reshape((5, 2))

# ## Access to elements

arr = np.random.randint(10, size=100).reshape((10, 10))
arr

arr[5,5]

arr[0,0]

arr[9,9]

arr[:,0]

arr[0,:]

arr[:3,:3]

arr > 5

arr[arr > 5]



StarcoderdataJupyterScriptsDedupFiltered