Talk:2D array

From GeoMod

Jump to: navigation, search

1. Why do we write "tiles[-1].x=(i-3) * dx"? I mean why do we write -1 with tiles? Is it subtract -1 from the number of tiles or is it for something else?

The -1 is to tell the program to look at the last tile in the list. If we create 5 tiles the tiles are numbered from 0 to 4. To address the last tile we can use tiles[4] or tiles[-1]. To address the second to last tile we use tiles[3] or tiles[-2]. Lurbano

2. What is

from random import uniform

Mmihir

This imports the "uniform" function from the "random" module of Python that was written by someone else. The uniform function generates a random number from a uniform distribution.
uniform(0.5,1) 
generates a random number between 0.5 and 1.
A module is a peice of code (functions etc) that is imported to be used in your code.
Personal tools