When I run the code python3 main.py to test my coding, it has the error as below
Here’s the link of my code
When I run the code python3 main.py to test my coding, it has the error as below
Here’s the link of my code
Can you paste your code here?
You cannot share your gitpod like this, you need to select sharing from the menu.
https://www.gitpod.io/docs/classic/user/configure/workspaces/collaboration
This is my code, but when running test it appeared the error below. Normally when I used the reshape() syntax, it worked, so I’m a bit confused here :
import numpy as np
def calculate(list):
# change list into an array
arr = np.array(list)
# Reshape into 3x3
matrix = arr.reshape(3, 3)
# Results
calculations = {
'mean': {
'rows': np.mean(matrix, axis=1),
'columns': np.mean(matrix, axis=0),
'flattened': np.mean(arr)
},
'variance': {
'rows': np.var(matrix, axis=1),
'columns': np.var(matrix, axis=0),
'flattened': np.var(arr)
},
'standard deviation': {
'rows': np.std(matrix, axis=1),
'columns': np.std(matrix, axis=0),
'flattened': np.std(arr)
},
'max': {
'rows': np.max(matrix, axis=1),
'columns': np.max(matrix, axis=0),
'flattened': np.max(arr)
},
'min': {
'rows': np.min(matrix, axis=1),
'columns': np.min(matrix, axis=0),
'flattened': np.min(arr)
},
'sum': {
'rows': np.sum(matrix, axis=1),
'columns': np.sum(matrix, axis=0),
'flattened': np.sum(arr)
}
}
return calculations
calculate(list)
I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
Can you please share a link to the exercise?
Are you getting an error because you are calling the function with an undefined variable?
calculate(list)
Call your function as instructed:
For example,
calculate([0,1,2,3,4,5,6,7,8])
should return: