These are just some basic array manipulation problems to get you used to working with NumPy arrays.
- Create a NumPy array of the integers 1 through 7.
- Set the first and last elements in the array to zero.
- Use
.sizeto determine the length of the array. - Sum all of the integers in the array.
- Using the results from parts 3 and 4, find the average of the array.
- Create a 1D NumPy array of 10,000 elements, all initially set to 0.0.
- Use a
whileloop and set every 101st element equal to1.0. (indices 0, 101, 202, 303, ...). - Change the shape of the array to be 100 x 100.
- Use a
forloop to set the first element of every row equal to the sum of all the values in that row. - Create a new array from the first elements in each of your rows. (HINT: You can make an array from a list.)
- Take the product of all the elements in your new array.
- Use
arangeto create an array of decimals from zero to 26. (HINT: dtype=float) - Reshape that array to be a 3 x 3 x 3 multi-dimensional array.
- Print the first and last element in the array, using three indexes.
- Using three
forloops, divide every number by thesumof all 3 elements in its row. - Calculate the
sumof all the elements in the array. - Create a new array, where every element is the square root of the old one.
- Calculate the product of all the elements in your new array.
- Use
np.onesto create an array,a, which is five elements long. - Use
np.arangeto create an array,b, which is the integers from 2 to 6 (five elements long). - Use
np.arangeto create an array,c, which is the even integers 2 to 12. (HINT: Withrange, you could do: range(min, max, step).) - Use
np.arangeto creat3 an array,d, which is the float values of the integers from 1 to 5. - Create a new array: x = c + a - b.
- What is the value of d - x?