-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquirk.py
More file actions
31 lines (31 loc) · 720 Bytes
/
Copy pathquirk.py
File metadata and controls
31 lines (31 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
#x is numpy ndarray
x=np.linspace(0,1,6)
#a is scalar, float in this case
a=3.5
#b is numpy ndarray of 1 element
b=np.array([3.0])
#runs ok
y=x*a;y2=x+a
print("scalar can be int of float")
print("ok: numpyarray * scalar")
print("ok: numpyarray + scalar")
y3=x*b;y4=b*x;y5=x+b;y6=b+x
print("ok: numpyarray * numpyarray")
print("ok: numpyarray + numpyarray")
#following operations give error
print("These operations give error")
print("on the Numworks calc:")
print("\"TypeError: Unsupported types\"")
try:
z=a*x
except:
print("error: scalar * numpyarray")
else:
print("ok: scalar * numpyarray")
try:
z2=a+x
except:
print("error: scalar + numpyarray")
else:
print("ok: scalar + numpyarray")