<jupyter_start><jupyter_text>100 numpy exercisesThis is a collection of exercises that have been collected in the numpy mailing list, on stack overflowand in the numpy documentation. The goal of this collection is to offer a quick reference for both oldand new users but also to provide a set of exercises for those who teach.If you find an error or think you've a better way to solve some of them, feelfree to open an issue at . File automatically generated. See the documentation to update questions/answers/hints programmatically. Run the `initialize.py` module, then for each question you can query theanswer or an hint with `hint(n)` or `answer(n)` for `n` question number.<jupyter_code>%run initialise.py<jupyter_output><empty_output><jupyter_text>1. Import the numpy package under the name `np` (★☆☆)<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>2. Print the numpy version and the configuration (★☆☆)<jupyter_code>print(np.__version__)
np.show_config()<jupyter_output>1.21.2
blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
    runtime_library_dirs = ['/usr/local/lib']
Supported SIMD extensions in this NumPy install:
    baseline = SSE,SSE2,SSE3
    found = SSS[...]<jupyter_text>3. Create a null vector of size 10 (★☆☆)<jupyter_code>a = np.zeros(10)
print(a)<jupyter_output>[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]<jupyter_text>4. How to find the memory size of any array (★☆☆)<jupyter_code>print(a.size * a.itemsize)<jupyter_output>80<jupyter_text>5. How to get the documentation of the numpy add function from the command line? (★☆☆)  6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)<jupyter_code>a[4] = 1
print(a)<jupyter_output>[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]<jupyter_text>7. Create a vector with values ranging from 10 to 49 (★☆☆)<jupyter_code>b = np.arange(10, 50)
print(b)<jupyter_output>[10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]<jupyter_text>8. Reverse a vector (first element becomes last) (★☆☆)<jupyter_code>z = b[::-1]
print(z)<jupyter_output>[49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26
 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10]<jupyter_text>9. Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)<jupyter_code>mat = np.arange(9).reshape(3, 3)
print(mat)<jupyter_output>[[0 1 2]
 [3 4 5]
 [6 7 8]]<jupyter_text>10. Find indices of non-zero elements from [1,2,0,0,4,0] (★☆☆)<jupyter_code>nz = np.nonzero([1,2,0,0,4,0])
print(nz)<jupyter_output>(array([0, 1, 4]),)
{'fraction_non_alphanumeric': 0.12578241430700446, 'fraction_numerical': 0.07481371087928465, 'mean_word_length': 4.43042071197411, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '84513', 'license': 'MIT', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1259, 'n_words': 409, 'path': '100_Numpy_exercises.ipynb', 'repo_name': 'Dashazyk/numpy-100', 'size': '3355'}