<jupyter_start><jupyter_text>Soring, searching, and counting<jupyter_code>import numpy as np
np.__version__
author = 'kyubyong. <EMAIL>'<jupyter_output><empty_output><jupyter_text>Sorting Q1. Sort x along the second axis.<jupyter_code>x = np.array([[1,4],[3,1]])<jupyter_output>[[1 4]
 [1 3]]<jupyter_text>Q2. Sort pairs of surnames and first names and return their indices. (first by surname, then by name).<jupyter_code>surnames =    ('Hertz',    'Galilei', 'Hertz')
first_names = ('Heinrich', 'Galileo', 'Gustav')<jupyter_output>[1 2 0]<jupyter_text>Q3. Get the indices that would sort x along the second axis.<jupyter_code>x = np.array([[1,4],[3,1]])<jupyter_output>[[0 1]
 [1 0]]<jupyter_text>Q4. Create an array such that its fifth element would be the same as the element of sorted x, and it divide other elements by their value.<jupyter_code>x = np.random.permutation(10)
print "x =", x<jupyter_output>x = [5 1 6 3 9 8 2 7 4 0]

Check the fifth element of this new array is 5, the first four elements are all smaller than 5, and 6th through the end are bigger than 5
[2 0 4 3 1 5 8 7 6 9]<jupyter_text>Q5. Create the indices of an array such that its third element would be the same as the element of sorted x, and it divide other elements by their value.<jupyter_code>x = np.random.permutation(10)
print "x =", x<jupyter_output>x = [2 8 3 7 5 6 4 0 9 1]
partitioned = [0 1 2 3 4 5 8 6 9 7]
indices = [0 1 2 3 4 5 8 6 9 7]<jupyter_text>Searching Q6. Get the maximum and minimum values and their indices of x along the second axis.<jupyter_code>x = np.random.permutation(10).reshape(2, 5)
print "x =", x<jupyter_output>x = [[0 5 9 8 2]
 [3 7 4 1 6]]
maximum values = [9 7]
max indices = [2 1]
minimum values = [0 1]
min indices = [0 3]<jupyter_text>Q7. Get the maximum and minimum values and their indices of x along the second axis, ignoring NaNs.<jupyter_code>x = np.array([[np.nan, 4], [3, 2]])<jupyter_output>maximum values ignoring NaNs = [ 4.  3.]
max indices = [1 0]
minimum values ignoring NaNs = [ 4.  2.]
min indices = [1 1]<jupyter_text>Q8. Get the values and indices of the elements that are bigger than 2 in x.<jupyter_code>x = np.array([[1, 2, 3], [1, 3, 5]])<jupyter_output>Values bigger than 2 = [3 3 5]
Their indices are  (array([0, 1, 1], dtype=int64), array([2, 1, 2], dtype=int64))<jupyter_text>Q9. Get the indices of the elements that are bigger than 2 in the flattend x.<jupyter_code>x = np.array([[1, 2, 3], [1, 3, 5]])<jupyter_output>[0 1 2 3 4 5]<jupyter_text>Q10. Check the elements of x and return 0 if it is less than 0, otherwise the element itself.<jupyter_code>x = np.arange(-5, 4).reshape(3, 3)<jupyter_output>[[0 0 0]
 [0 0 0]
 [1 2 3]]<jupyter_text>Q11. Get the indices where elements of y should be inserted to x to maintain order.<jupyter_code>x = [1, 3, 5, 7, 9]
y = [0, 4, 2, 6]<jupyter_output><empty_output><jupyter_text>Counting Q12. Get the number of nonzero elements in x.<jupyter_code>x = [[0,1,7,0,0],[3,0,0,2,19]]<jupyter_output>5
{'fraction_non_alphanumeric': 0.12877263581488935, 'fraction_numerical': 0.06539235412474849, 'mean_word_length': 4.769825918762089, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '364470', 'license': 'MIT', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1140, 'n_words': 421, 'path': 'Sorting_searching_and_counting.ipynb', 'repo_name': 'server73/numpy_excercises', 'size': '2995'}