abbasasfaq/untitled

2 months ago

My first markdown cell

My first markdown cell

My first

My first

my-first

mazoon college

In [1]:
``w1, w2, w3 = 0.3, 0.2, 0.5``
In [2]:
``````kanto_temp=73
kanto_railfall = 67
kanto_humidity = 43``````
In [3]:
``kanto_yield_apples = kanto_temp* w1+kanto_railfall*w2+kanto_humidity*w3``
In [4]:
``kanto_yield_apples``
Out[4]:
``56.8``
In [5]:
``print("The expected yield of apples in Kanto region is {} tons per hectare.".format(kanto_yield_apples))``
```The expected yield of apples in Kanto region is 56.8 tons per hectare. ```
In [6]:
``````kanto = [73, 67, 43]
johto = [91, 88, 64]
hoenn = [87, 134, 58]
sinnoh = [102, 43, 37]
unova = [69, 96, 70]``````
In [7]:
``weights = [w1, w2, w3]``
In [8]:
``````def crop_yield(region, weights):
result = 0
for x, w in zip(region, weights):
result += x * w
return result``````
In [9]:
``crop_yield(kanto,weights)``
Out[9]:
``56.8``
In [10]:
``````crop_yield(johto, weights)

``````
Out[10]:
``76.9``

The Numpy library provides a built-in function to compute the dot product of two vectors. However, we must first convert the lists into Numpy arrays.

Let's install the Numpy library using the pip package manager.

In [ ]:
``!pip install numpy --upgrade --quiet``

Next, let's import the numpy module. It's common practice to import numpy with the alias np.

In [4]:
``import numpy as np``
In [15]:
``kanto = np.array([73, 67, 43])``
In [16]:
``kanto``
Out[16]:
``array([73, 67, 43])``
In [17]:
``weights = np.array([w1, w2, w3])``
In [18]:
``weights``
Out[18]:
``array([0.3, 0.2, 0.5])``
In [19]:
``type(kanto)``
Out[19]:
``numpy.ndarray``
In [20]:
``weights[0]``
Out[20]:
``0.3``
In [21]:
``np.dot(kanto, weights)``
Out[21]:
``56.8``
In [22]:
``(kanto*weights).sum()``
Out[22]:
``56.8``
In [26]:
``import jovian``
In [27]:
``jovian.commit()``
```[jovian] Attempting to save notebook.. [jovian] Updating notebook "abbasasfaq/untitled" on https://jovian.ai/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ai/abbasasfaq/untitled ```
Out[27]:
``'https://jovian.ai/abbasasfaq/untitled'``
In [28]:
``````climate_date = np.array([[73, 67, 43],
[91, 88, 64],
[87, 134, 58],
[102, 43, 37],
[69, 96, 70]
])
``````
In [29]:
``climate_date``
Out[29]:
``````array([[ 73,  67,  43],
[ 91,  88,  64],
[ 87, 134,  58],
[102,  43,  37],
[ 69,  96,  70]])``````
In [30]:
``climate_data.shape``
```--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-30-f985d38975f7> in <module> ----> 1 climate_data.shape NameError: name 'climate_data' is not defined```
In [31]:
``climate_date.shape``
Out[31]:
``(5, 3)``
In [32]:
``weights``
Out[32]:
``array([0.3, 0.2, 0.5])``
In [33]:
``weights.shape``
Out[33]:
``(3,)``
In [34]:
``````arr3 = np.array([
[[11, 12, 13]
[13, 14, 15]],
[[15, 16, 17],
[17, 18, 19.5]]])``````
```<>:2: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma? <>:2: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma? <ipython-input-34-e42dd46a88e8>:2: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma? [[11, 12, 13] ```
```--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-34-e42dd46a88e8> in <module> 1 arr3 = np.array([ ----> 2 [[11, 12, 13] 3 [13, 14, 15]], 4 [[15, 16, 17], 5 [17, 18, 19.5]]]) TypeError: list indices must be integers or slices, not tuple```
In [35]:
``````# 3D array
arr3 = np.array([
[[11, 12, 13],
[13, 14, 15]],
[[15, 16, 17],
[17, 18, 19.5]]])``````
In [36]:
``arr3.shape``
Out[36]:
``(2, 2, 3)``
In [37]:
``np.matmul(climate_date, weights)``
Out[37]:
``array([56.8, 76.9, 81.9, 57.7, 74.9])``
In [38]:
``climate_date @ weights``
Out[38]:
``array([56.8, 76.9, 81.9, 57.7, 74.9])``
In [2]:
``````import urllib.request

urllib.request.urlretrieve(
'climate.txt')``````
Out[2]:
``('climate.txt', <http.client.HTTPMessage at 0x7fb7f6464970>)``
In [12]:
``climate_data = np.genfromtxt('climate.txt', delimiter=',', skip_header=1)``
In [13]:
``climate_data``
Out[13]:
``````array([[25., 76., 99.],
[39., 65., 70.],
[59., 45., 77.],
...,
[99., 62., 58.],
[70., 71., 91.],
[92., 39., 76.]])``````
In [14]:
``climate_data.shape``
Out[14]:
``(10000, 3)``
In [15]:
``weights = np.array([0.3, 0.2, 0.5])``
In [16]:
``yields = climate_data @ weights``
In [17]:
``yields``
Out[17]:
``array([72.2, 59.7, 65.2, ..., 71.1, 80.7, 73.4])``
In [18]:
``yields.shape``
Out[18]:
``(10000,)``
In [21]:
``climate_results = np.concatenate((climate_data, yields.reshape(10000, 1)), axis=0)``
```--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-21-6d59f9153327> in <module> ----> 1 climate_results = np.concatenate((climate_data, yields.reshape(10000, 1)), axis=0) <__array_function__ internals> in concatenate(*args, **kwargs) ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 3 and the array at index 1 has size 1```
In [20]:
``climate_results``
Out[20]:
``````array([[25. , 76. , 99. , 72.2],
[39. , 65. , 70. , 59.7],
[59. , 45. , 77. , 65.2],
...,
[99. , 62. , 58. , 71.1],
[70. , 71. , 91. , 80.7],
[92. , 39. , 76. , 73.4]])``````
In [24]:
``climate_results = np.concatenate((climate_data, yields.reshape(10000, 1)), axis=1)``
In [25]:
``climate_results``
Out[25]:
``````array([[25. , 76. , 99. , 72.2],
[39. , 65. , 70. , 59.7],
[59. , 45. , 77. , 65.2],
...,
[99. , 62. , 58. , 71.1],
[70. , 71. , 91. , 80.7],
[92. , 39. , 76. , 73.4]])``````
In [26]:
``````np.savetxt('climate_results.txt',
climate_results,
fmt='%.2f',
delimiter=',',
``!pip install jovian --upgrade --quiet``
``import jovian``
``jovian.commit()``
```[jovian] Attempting to save notebook.. ```
`` ``