Answer To: CP5805 Assignment 1 - Main task The main task is to write a program to assist a trader with entering...
Aditya answered on May 30 2021
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CP5805 Practical 4 - double-click and type your name here\n",
"\n",
"Once you've completed these tasks, name your file as `Lastname_Firstname_prac_4.ipynb` and submit on LearnJCU.\n",
"E.g., if your name is Alice Smith, your file should be called `Smith_Alice_prac_4.ipynb`"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task 1\n",
"Create an ndarray based on the following list:\n",
"```python\n",
"data = [43, 23, 65, 23, 56, 989, 23, 54, 54]\n",
"```\n",
"Then display:\n",
"* the whole array\n",
"* the first five elements (using slicing)\n",
"* the size\n",
"* the shape\n",
"* the dimensionality\n",
"* the array with each element multiplied by 5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"data = np.array([43,23,65,23,56,989,23,54,54])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Printing elements of array: [ 43 23 65 23 56 989 23 54 54]\n",
"Array after slicing: [43 23 65 23 56]\n",
"Size of array: 9\n",
"Shape of array: (9,)\n",
"Dimension of array: 1\n",
"Multipled Array: [ 215 115 325 115 280 4945 115 270 270]\n"
]
}
],
"source": [
"\n",
"\n",
"print('Printing elements of array: ',data)\n",
"newData = data[:5]\n",
"print('Array after slicing: ',newData)\n",
"print('Size of array: ', data.size)\n",
"print ('Shape of array: ',data.shape)\n",
"print('Dimension of array: ',data.ndim)\n",
"mulitpledArray = data * 5\n",
"print('Multipled Array: ',mulitpledArray)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Task 2\n",
"Create a 5×5 numpy array with numbers between 1 and 100.\n",
"\n",
"Based on the first array, create a new array *where*:\n",
"* the value is 0 if the original array had a value <= 50\n",
"* the value is twice the original value if the array had a value of > 50\n",
"\n",
"(e.g. if the original array were `[26, 51, 19]`, the...