Browse Source

Erster Schwung für Teil 22

master
Olli Graf 10 months ago
parent
commit
0882dd06f3
  1. 4
      teil22/.gitignore
  2. 18
      teil22/StressFile.py
  3. 42
      teil22/calc_array.py
  4. 20
      teil22/copyarray.py
  5. 9
      teil22/reshape.py
  6. 7
      teil22/rndm.py
  7. 6
      teil22/shape.py
  8. 9
      teil22/simplearray.py
  9. 9
      teil22/twodimarray.py

4
teil22/.gitignore

@ -0,0 +1,4 @@
# created by virtualenv automatically
__pycache__
bin
lib

18
teil22/StressFile.py

@ -0,0 +1,18 @@
import io
import numpy as np
class StressFile:
def readOutFile(self,filename):
result = {
'frequency': [],
'temperatures': []
}
with open(filename,'r') as f:
content = f.readlines()
print(f'conent= {content}')
sf = StressFile()
sf.readOutFile('./kodos.out')

42
teil22/calc_array.py

@ -0,0 +1,42 @@
import numpy as np
# Array initialisieren
org = np.array([1,2,3,4,5,6])
# Kopiert das int64 Array in ein float64 Array
def copy_to_float64(source):
liste = []
for i in range(source.shape[1]):
liste.append(float(source[i]))
return np.array(liste,dtype=float64)
# Ein paar Kopien anlegen
copy_sum = org.copy()
copy_mult = org.copy()
copy_diff = org.copy()
copy_div = org.astype(np.float64).copy()
# Zu allen Elementen 2 dazuzählen
copy_sum += 2
print(f'copy_sum={copy_sum}')
# Alle Elemente mit 2 multiplizieren
copy_mult *= 2
print(f'copy_mult={copy_mult}')
# Von allen Elementen 1 abziehen
copy_diff -= 1
print(f'copy_diff={copy_diff}')
copy_div /=2
print(f'copy_div={copy_div}')

20
teil22/copyarray.py

@ -0,0 +1,20 @@
import numpy as np
org = np.array([1,2,3,4,5,6])
copy = org
print(f'org= {org}')
print(f'copy={copy}')
copy[2]= 7
print(f'org= {org}')
print(f'copy={copy}')
copy2 = org.copy()
copy2[2]= 3
print(f'org= {org}')
print(f'copy2={copy2}')

9
teil22/reshape.py

@ -0,0 +1,9 @@
import numpy as np
a = np.array([1,2,3,4,5,6,7,8,9,10])
print(f'orignal {a}')
reshaped = a.reshape(2,5)
print(f'reshaped {reshaped}')

7
teil22/rndm.py

@ -0,0 +1,7 @@
import numpy as np
#Erzeuge 1 Mio Zufallszahlen
random_np = np.random(100000)
random_list = list(random_np)

6
teil22/shape.py

@ -0,0 +1,6 @@
import numpy as np
twodim_array = np.array([[1,2,3,4,5],[1,4,9,16,25]])
print(f'shape is {twodim_array.shape}')

9
teil22/simplearray.py

@ -0,0 +1,9 @@
import numpy as np
simple_array = np.array([1,2,3,4,5,6])
print(f'simple_array={simple_array}')
print(f'ndim={simple_array.ndim}')
print(f'dtype={simple_array.dtype}')
print(f'shape is {simple_array.shape}')

9
teil22/twodimarray.py

@ -0,0 +1,9 @@
import numpy as np
twodim_array = np.array([[1,2,3,4,5],[1,4,9,16,25]],dtype='int32')
print(f'twodim_array={twodim_array}')
print(f'ndim={twodim_array.ndim}')
print(f'dtype={twodim_array.dtype}')
print(f'shape is {twodim_array.shape}')
Loading…
Cancel
Save