I would like to calculate the average value of each line in the following files using Python.
A=8×8 matrix
So I wrote the following code, but it turned out to be an error.
What should I do?
code:
import numpy as np
f = open ('A')
lines=f.readlines()
print(np.mean(lines,axis=0))
error messages:
Traceback (most recent call last):
File "ave.py", line 6, in <module>
print(np.mean(lines,axis=0))
File"/usr/lib64/python 2.7/site-packages/numpy/core/fromnumeric.py", line2488, in mean
out=out, keepdims=keepdims)
File"/usr/lib64/python 2.7/site-packages/numpy/core/_methods.py", line51, in_mean
out=out, keepdims=keepdims)
TypeError: cannot perform redundancy with flexible type
3x3 matrix for example
print(A)
array([1,2,3],
[4, 5, 6],
[7, 8, 9]])
np.mean(A,axis=1)
array([2.,5.,8.])
np.mean(A,axis=0)
array([4.,5.,6.])
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.