<jupyter_start><jupyter_text>Exercise 2: Interrogating and manipulating arraysAim: Learn how to interrogate and manipulate NumPy arraysIn this exercise we refers to a useful guide that can help you solve any questions in NumPy. This guide also summarize all that is needed to know about NumPy. [link to the guide](https://drive.google.com/file/d/0B9crmgoWupXkLTh0TS1HMzlrSVk/view)Issue covered:*   Intertogating the properties of an array*   Manipulating arrays to change their properties.<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>1.  Let’s interrogate an array to find out its characteristics.Recall what you’ve read in Exercise 1, read page 11 and then: >(a)  Create a 2-D array shape (2,4) containing two lists: (range(4), range(10, 14)) and assign it to the variable "arr") :<jupyter_code># Your Code Here#
import numpy 
arr = numpy.array([range(4), range(10,14)])

print(arr)<jupyter_output>[[ 0  1  2  3]
 [10 11 12 13]]<jupyter_text>>(b) Print the shape of the array :<jupyter_code>import numpy 
print (arr.shape)<jupyter_output>(2, 4)<jupyter_text>>(c)  Print the size of the array:<jupyter_code>import numpy 
print (arr.size)<jupyter_output>8<jupyter_text>>(d)  Print the maximum and minimum of the array:<jupyter_code>print (numpy.amax(arr))
print (numpy.amin(arr))<jupyter_output>13
0<jupyter_text>2. Let’s generate new arrays by modifying our array.Read the last code chunk on page 4 and read on until page 7  	(up to “Other ways to create arrays” you’ve already read). Then: >(a)  Continue to use the array "arr" as defined above: > (b) Re-shape array "arr" to (2, 2, 2) and print it:<jupyter_code>numpy.reshape(arr,(2,2,2))<jupyter_output><empty_output><jupyter_text>>(c)  Print the array transposed:<jupyter_code>print (numpy.transpose(arr))<jupyter_output>[[ 0 10]
 [ 1 11]
 [ 2 12]
 [ 3 13]]<jupyter_text>>(d)  Print the array flattened to a single dimension:<jupyter_code># Your Code Here#
print (numpy.reshape(arr,-1))<jupyter_output>[ 0  1  2  3 10 11 12 13]<jupyter_text>>(e)  Print the array converted to floats:<jupyter_code># Your Code Here#
arr.astype(numpy. float)<jupyter_output><empty_output><jupyter_text>>(f) Create a 2-D array shape (2, 4) containing two lists [0, 3.1, 2.2, 1.1] and [7, 4, 3.14, 11] and assign it to the variable "arr2":<jupyter_code># Your Code Here#
arr2 = numpy.array([(0, 3.1, 2.2, 1.1), (7, 4, 3.14, 11)])
print(arr2)<jupyter_output><empty_output><jupyter_text>>(g) Use  concatenate  function to concatenate "arr" and "arr2":<jupyter_code># Your Code Here#
arr_conc = numpy.concatenate((arr,arr2))

print(arr_conc)<jupyter_output>[[ 0.    1.    2.    3.  ]
 [10.   11.   12.   13.  ]
 [ 0.    3.1   2.2   1.1 ]
 [ 7.    4.    3.14 11.  ]]<jupyter_text>> (h) As you’ve read on page 7, you can use newaxis function to expand the shape of a 1-D array. In the case of multidimensional arrays you can use expand_dims function as shown here. Use expand_dims function and print "arr" array re-shaped to (2, 4, 1):<jupyter_code>arr=numpy.reshape(arr,(2,4,1))
print (arr)<jupyter_output>[[[ 0]
  [ 1]
  [ 2]
  [ 3]]

 [[10]
  [11]
  [12]
  [13]]]
{'fraction_non_alphanumeric': 0.12928, 'fraction_numerical': 0.04992, 'mean_word_length': 4.87593984962406, 'pattern_counts': {'":': 2, '<': 41, '<?xml version=': 0, '>': 53, 'https://': 1, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '419658', 'license': 'Apache-2.0', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1181, 'n_words': 377, 'path': 'Exercise_2_Interrogating_and_manipulating_arrays.ipynb', 'repo_name': 'talsarig/devart-template', 'size': '3125'}