<jupyter_start><jupyter_text>Example 1 Basic slicing is an extension of Python's basic concept of slicing to n dimensions. A Python slice object is constructed by giving start, stop, and step parameters to the built-in slice function. This slice object is passed to the array to extract a part of array.<jupyter_code>import numpy as np 
a = np.arange(10) 
s = slice(2,7,2) 
print(a[s])<jupyter_output>[2 4 6]<jupyter_text>In the above example, an ndarray object is prepared by arange() function. Then a slice object is defined with start, stop, and step values 2, 7, and 2 respectively. When this slice object is passed to the ndarray, a part of it starting with index 2 up to 7 with a step of 2 is sliced.  Example 2 The same result can also be obtained by giving the slicing parameters separated by a colon : (start:stop:step) directly to the ndarray object.<jupyter_code>import numpy as np 
a = np.arange(10) 
b = a[2:7:2] 
print(b)<jupyter_output>[2 4 6]<jupyter_text>Example 3 If only one parameter is put, a single item corresponding to the index will be returned. If a : is inserted in front of it, all items from that index onwards will be extracted. If two parameters (with : between them) is used, items between the two indexes (not including the stop index) with default step one are sliced.<jupyter_code># slice single item 
import numpy as np 

a = np.arange(10) 
b = a[5] 
print(b)
# slice items starting from index 
import numpy as np 
a = np.arange(10) 
print(a[2:])
# slice items between indexes 
import numpy as np 
a = np.arange(10) 
print(a[2:5])<jupyter_output>[2 3 4]<jupyter_text>The above description applies to multi-dimensional ndarray too.<jupyter_code>import numpy as np 
a = np.array([[1,2,3],[3,4,5],[4,5,6]]) 
print(a)  

# slice items starting from index
print('Now we will slice the array from the index a[1:]') 
print(a[1:])<jupyter_output>[[1 2 3]
 [3 4 5]
 [4 5 6]]
Now we will slice the array from the index a[1:]
[[3 4 5]
 [4 5 6]]<jupyter_text>Example 4 Slicing can also include ellipsis (…) to make a selection tuple of the same length as the dimension of an array. If ellipsis is used at the row position, it will return an ndarray comprising of items in rows.<jupyter_code># array to begin with 
import numpy as np 
a = np.array([[1,2,3],[3,4,5],[4,5,6]]) 

print('Our array is:') 
print(a)
print('\n')  

# this returns array of items in the second column 
print('The items in the second column are:')
print(a[...,1]) 
print('\n')  

# Now we will slice all items from the second row 
print('The items in the second row are:')
print(a[1,...])
print('\n')

# Now we will slice all items from column 1 onwards 
print('The items column 1 onwards are:')
print(a[...,1:])<jupyter_output>Our array is:
[[1 2 3]
 [3 4 5]
 [4 5 6]]


The items in the second column are:
[2 4 5]


The items in the second row are:
[3 4 5]


The items column 1 onwards are:
[[2 3]
 [4 5]
 [5 6]]
{'fraction_non_alphanumeric': 0.10237031947784267, 'fraction_numerical': 0.03503950532463071, 'mean_word_length': 4.265822784810126, 'pattern_counts': {'":': 0, '<': 16, '<?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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '106724', 'license': 'MIT', 'n_tokens_mistral': 1036, 'n_tokens_neox': 967, 'n_words': 447, 'path': 'tf/example/numpy.ipynb', 'repo_name': 'tolkien/misc', 'size': '2911'}