<jupyter_start><jupyter_text>The Robot WorldA robot, much like you, perceives the world through its "senses." For example, self-driving cars use video, radar, and Lidar, to observe the world around them. As cars gather data, they build up a 3D world of observations that tells the car where it is, where other objects (like trees, pedestrians, and other vehicles) are, and where it should be going! In this section, we'll be working with a 2D representation of the world for simplicity, and because two dimensions are often all you'll need to solve a certain problem.  2D Arrays This demonstration shows how to represent a robot's world as a 2D array of observations, in this case, we'll work with a simple example that uses  integer variables to represent whether there is (1) or is not (0) a tree present at that location on the grid.For example, a robot that sees a 2x4 world may see this 2D array:```python[[0, 0, 0, 1], [1, 0, 0, 0]]```Which indicates that there are only two trees: one at the top rightmost point in its world, and one at the leftmost bottom. In fact the coordinates or indices of these tree locations are [0, 3] for the top-right corner and [1, 0] for the bottom-left. This has to do with the way indices are counted in Python. A graphical representation is shown below. Note that in this demonstration, we'll be using the `numpy` library again, which is a Python library that helps us create and manipulate arrays. Define the 2D world<jupyter_code>import numpy as np

# A simple robot world can be defined by a 2D array
# Here is a 6x5 (num_rows x num_cols) world
world = np.array([ [0, 0, 0, 1, 0],
                   [0, 0, 0, 1, 0],
                   [0, 1, 1, 0, 0],
                   [0, 0, 0, 0, 1],
                   [1, 0, 0, 1, 0],
                   [1, 0, 0, 0, 0] ])

# Visualize the world
print(world)
# Print out some information about the world

print('The shape of this array is: ' + str(world.shape))
print('Notice that the number of rows come before the number of columns!')
print('It\'s height is: ' + str(world.shape[0]) + 
      ', and it\'s width is: ' + str(world.shape[1]))<jupyter_output><empty_output><jupyter_text>Read and compare values in a 2D array<jupyter_code># Access a location and read its value
value = world[3][0]
print('\n')
print('Value at index [3, 0] = ' +str(value))

# Read the first three items in the 3rd row
row = 2
column_index = 0
value_left = world[row, column_index]
value_middle = world[row, column_index + 1]
value_right = world[row, column_index + 2]

print('\nThe first three values in row 2 : ' +str(value_left)+', '
                                              +str(value_middle) +', '
                                              +str(value_right) )

# Compare the first two values and print the result
compare = world[0][0] == world[0][1]
print('\nDo the first two values match? ' + str(compare))<jupyter_output><empty_output><jupyter_text>Change an Array and Plant a Tree!<jupyter_code># Define a function to plant a tree 
# and change the value of the array in that location
def plant_tree(y, x):
    # check that the indices are in the boundaries of the array dimensions
    if(y < world.shape[0] and x < world.shape[1]):
        world[y,x] = 1
        print('\n' + str(world)) # prints a newline and the current world

# Call the function at the location x = 3, and y = 2
# You can call this multiple times in a row
plant_tree(0, 2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09209383145091225, 'fraction_numerical': 0.0228786562409499, 'mean_word_length': 3.3391959798994977, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '642995', 'license': 'MIT', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1001, 'n_words': 497, 'path': '1_Robot_Localization/.ipynb_checkpoints/2D Arrays and the Robot World, demonstration-checkpoint.ipynb', 'repo_name': 'sandeeppaulraj/CVND_Localization_Exercises', 'size': '3453'}