<jupyter_start><jupyter_text>Array manipulations * Form the 2-D array (without typing it in explicitly):    [[1,  6, 11],     [2,  7, 12],     [3,  8, 13],     [4,  9, 14],     [5, 10, 15]]    and generate a new array containing its 2nd and 4th rows.<jupyter_code>import numpy as np

import matplotlib.pyplot as plt
%matplotlib inline
a = np.arange(1, 16).reshape(3, 5).T
a
b = a[1:5:2]
b<jupyter_output><empty_output><jupyter_text>* Divide each column of the array:<jupyter_code>a = np.arange(25).reshape(5, 5)
a
b = a[:, np.newaxis].T
b<jupyter_output><empty_output><jupyter_text>* Generate a 10 x 3 array of random numbers (in range [0,1]). For each row, pick the number closest to 0.5.    * Use abs and argsort to find the column j closest for each row.    * Use fancy indexing to extract the numbers. (Hint: a[i,j] – the array i must contain the row numbers corresponding to stuff in j.)<jupyter_code>a = np.random.rand(30).reshape(10, 3)
a<jupyter_output><empty_output><jupyter_text>Data statistics<jupyter_code>data = np.loadtxt('data/populations.txt')
year, hares, lynxes, carrots = data.T
year
plt.axes([0.2, 0.1, 0.5, 0.8])

plt.plot(year, hares, year, lynxes, year, carrots)

plt.legend(('hare', 'lynx', 'carrot'), loc=(1.05, 0.5))
image = np.random.rand(30, 30)
plt.imshow(image, cmap=plt.cm.hot)
plt.colorbar()
plt.show()
def compute_mandelbrot(N_max, some_threshold, nx, ny):
    # A grid of c-values
    x = np.linspace(-2, 1, nx)
    y = np.linspace(-1.5, 1.5, ny)

    c = x[:, np.newaxis] + 1j*y[np.newaxis, :]

    # Mandelbrot iteration

    z = c
    for j in range(N_max):
        z = z**2 + c

    mandelbrot_set = (abs(z) < some_threshold)

    return mandelbrot_set

mandelbrot_set = compute_mandelbrot(50, 50., 601, 401)

plt.imshow(mandelbrot_set.T, extent=[-2, 1, -1.5, 1.5])
plt.gray()
plt.show()<jupyter_output>C:\Users\Sourav\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:12: RuntimeWarning: overflow encountered in square
  if sys.path[0] == '':
C:\Users\Sourav\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:12: RuntimeWarning: invalid value encountered in square
  if sys.path[0] == '':
C:\Users\Sourav\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:14: RuntimeWarning: invalid value encountered in less
{'fraction_non_alphanumeric': 0.14852752880921896, 'fraction_numerical': 0.04139991463935126, 'mean_word_length': 4.2674157303370785, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '403594', 'license': 'MIT', 'n_tokens_mistral': 1000, 'n_tokens_neox': 923, 'n_words': 229, 'path': 'Numpy/.ipynb_checkpoints/Some_exercises-checkpoint.ipynb', 'repo_name': 'SrGrace/DataScience_Jupyter_Notebook', 'size': '2343'}