<jupyter_start><jupyter_text>NumPy Basics Task 1 Make sure that NumPy is imported to your IPython shell<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>a) Generate an arbitrary one dimensional array `n` with `n.shape=(8,)` and display it.<jupyter_code>n = np.array([3,8,12,18,7,11,30])
print(n)<jupyter_output>[ 3  8 12 18  7 11 30]<jupyter_text>b) Create a new array `n_odd` which consists of the odd entries of `n`. Display it.<jupyter_code>n_odd = n[1::2]
print(n_odd)<jupyter_output>[ 8 18 11]<jupyter_text>c) Create a new array `n_rev` which contains the entries of `n` in reverse order. Display it.<jupyter_code>n_rev = n[::-1]
print(n_rev)<jupyter_output>[30 11  7 18 12  8  3]<jupyter_text>d) What would be the output of the following code?<jupyter_code>a = np.array([1, 2, 3, 4, 5])
b = a[1:4]
b[0] = 200
print(a[1])<jupyter_output>200<jupyter_text>e) Create a two-dimensional array called `m` with `m.shape=(3,4)` and display it.<jupyter_code>m = np.array([[11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34]])
print(m)<jupyter_output>[[11 12 13 14]
 [21 22 23 24]
 [31 32 33 34]]<jupyter_text>Create another array `m_revrowel` which contains the same elements as `m`, but with reversed rows. Display it.<jupyter_code>m_revrowel = m[:, ::-1]
print(m_revrowel)<jupyter_output>[[14 13 12 11]
 [24 23 22 21]
 [34 33 32 31]]<jupyter_text>Create yet another array `m_revall` which contains the same elements as `m`, but with reversed rows and columns. Display it.<jupyter_code>m_revall = m[::-1, ::-1]
print(m_revall)<jupyter_output>[[34 33 32 31]
 [24 23 22 21]
 [14 13 12 11]]<jupyter_text>Create an array `m_cut` which contains only the elements from the first and last rows and columns of `m`. Display it.<jupyter_code>m_cut = m[(0,-1),:][:,(0,-1)]
print(m_cut)<jupyter_output>[[11 14]
 [31 34]]
{'fraction_non_alphanumeric': 0.14683406113537117, 'fraction_numerical': 0.09334061135371179, 'mean_word_length': 5.788888888888889, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '60304', 'license': 'Apache-2.0', 'n_tokens_mistral': 868, 'n_tokens_neox': 731, 'n_words': 224, 'path': 'information-retrieval-exercises/solutions/lab01_solution.ipynb', 'repo_name': 'achmart/inforet', 'size': '1832'}