|
29 | 29 | }, |
30 | 30 | { |
31 | 31 | "cell_type": "code", |
32 | | - "execution_count": null, |
| 32 | + "execution_count": 1, |
33 | 33 | "metadata": {}, |
34 | 34 | "outputs": [], |
35 | 35 | "source": [ |
36 | 36 | "# Import NumPy \n", |
37 | | - "None" |
| 37 | + "import numpy as np" |
38 | 38 | ] |
39 | 39 | }, |
40 | 40 | { |
|
49 | 49 | }, |
50 | 50 | { |
51 | 51 | "cell_type": "code", |
52 | | - "execution_count": null, |
| 52 | + "execution_count": 2, |
53 | 53 | "metadata": {}, |
54 | | - "outputs": [], |
| 54 | + "outputs": [ |
| 55 | + { |
| 56 | + "name": "stdout", |
| 57 | + "output_type": "stream", |
| 58 | + "text": [ |
| 59 | + "[1 2 3 4 5]\n" |
| 60 | + ] |
| 61 | + } |
| 62 | + ], |
55 | 63 | "source": [ |
56 | | - "points = None\n", |
| 64 | + "points = np.array([1,2,3,4,5])\n", |
57 | 65 | "print(points)" |
58 | 66 | ] |
59 | 67 | }, |
|
70 | 78 | }, |
71 | 79 | { |
72 | 80 | "cell_type": "code", |
73 | | - "execution_count": null, |
| 81 | + "execution_count": 4, |
74 | 82 | "metadata": {}, |
75 | 83 | "outputs": [], |
76 | 84 | "source": [ |
77 | 85 | "# Create a 2D array for player stats\n", |
78 | 86 | "# Example: [[points, rebounds, assists], ...]\n", |
79 | 87 | "\n", |
80 | | - "player_stats = None" |
| 88 | + "player_stats = np.array([\n", |
| 89 | + " [32, 22, 14],\n", |
| 90 | + " [32, 12, 10],\n", |
| 91 | + " [5, 2, 10],\n", |
| 92 | + " [12, 20, 2],\n", |
| 93 | + " [5, 19, 4]\n", |
| 94 | + "])\n" |
81 | 95 | ] |
82 | 96 | }, |
83 | 97 | { |
|
93 | 107 | }, |
94 | 108 | { |
95 | 109 | "cell_type": "code", |
96 | | - "execution_count": null, |
| 110 | + "execution_count": 9, |
97 | 111 | "metadata": {}, |
98 | | - "outputs": [], |
| 112 | + "outputs": [ |
| 113 | + { |
| 114 | + "name": "stdout", |
| 115 | + "output_type": "stream", |
| 116 | + "text": [ |
| 117 | + "[68 54 17 34 28]\n" |
| 118 | + ] |
| 119 | + } |
| 120 | + ], |
99 | 121 | "source": [ |
100 | 122 | "# Calculate total stats for each player\n", |
| 123 | + "\n", |
101 | 124 | "total_stats = np.sum(player_stats, axis=1)\n", |
102 | 125 | "print(total_stats)" |
103 | 126 | ] |
|
113 | 136 | }, |
114 | 137 | { |
115 | 138 | "cell_type": "code", |
116 | | - "execution_count": null, |
| 139 | + "execution_count": 5, |
117 | 140 | "metadata": {}, |
118 | | - "outputs": [], |
| 141 | + "outputs": [ |
| 142 | + { |
| 143 | + "name": "stdout", |
| 144 | + "output_type": "stream", |
| 145 | + "text": [ |
| 146 | + "[[32 32 5 12 5]\n", |
| 147 | + " [22 12 2 20 19]\n", |
| 148 | + " [14 10 10 2 4]]\n" |
| 149 | + ] |
| 150 | + } |
| 151 | + ], |
119 | 152 | "source": [ |
120 | 153 | "# Transpose the array\n", |
121 | | - "transposed_stats = None\n", |
| 154 | + "transposed_stats = player_stats.transpose()\n", |
122 | 155 | "print(transposed_stats)" |
123 | 156 | ] |
124 | 157 | }, |
|
135 | 168 | }, |
136 | 169 | { |
137 | 170 | "cell_type": "code", |
138 | | - "execution_count": null, |
| 171 | + "execution_count": 7, |
139 | 172 | "metadata": {}, |
140 | | - "outputs": [], |
| 173 | + "outputs": [ |
| 174 | + { |
| 175 | + "name": "stdout", |
| 176 | + "output_type": "stream", |
| 177 | + "text": [ |
| 178 | + "[[1. 0.64299603]\n", |
| 179 | + " [0.64299603 1. ]]\n" |
| 180 | + ] |
| 181 | + } |
| 182 | + ], |
141 | 183 | "source": [ |
142 | 184 | "# Calculate correlation between points and assists -- what does the output mean?\n", |
143 | 185 | "\n", |
144 | | - "correlation = None(player_stats[:, 0], player_stats[:, 2])\n", |
| 186 | + "correlation = np.corrcoef(player_stats[:, 0], player_stats[:, 2])\n", |
145 | 187 | "print(correlation)" |
146 | 188 | ] |
147 | 189 | }, |
|
171 | 213 | }, |
172 | 214 | { |
173 | 215 | "cell_type": "code", |
174 | | - "execution_count": null, |
| 216 | + "execution_count": 15, |
175 | 217 | "metadata": {}, |
176 | | - "outputs": [], |
| 218 | + "outputs": [ |
| 219 | + { |
| 220 | + "name": "stdout", |
| 221 | + "output_type": "stream", |
| 222 | + "text": [ |
| 223 | + "Player with the highest total stats: Player 3\n", |
| 224 | + "Total stats: 46\n" |
| 225 | + ] |
| 226 | + } |
| 227 | + ], |
177 | 228 | "source": [ |
178 | 229 | "# Player stats array\n", |
179 | 230 | "player_stats = np.array([\n", |
|
185 | 236 | "])\n", |
186 | 237 | "\n", |
187 | 238 | "# Calculate total stats for each player\n", |
188 | | - "total_stats = None\n", |
| 239 | + "total_stats = np.sum(player_stats, axis=1)\n", |
189 | 240 | "\n", |
190 | 241 | "# Find the index of the player with the highest total stats\n", |
191 | | - "best_player_index = None\n", |
| 242 | + "best_player_index = np.argmax(total_stats)\n", |
192 | 243 | "\n", |
193 | 244 | "# Print the result\n", |
194 | 245 | "print(f\"Player with the highest total stats: Player {best_player_index + 1}\")\n", |
|
0 commit comments