Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download

Jupyter notebook Linspace_Experiments.ipynb

Views: 178
Kernel: Python 3 (system-wide)

Experiments in linspace and numpy types

This file contains come linspace experiments, a bit of for comprehension to cast the type to int. Basic refresher stuff. At the end we'll try to create an int array directly by setting dtype, then wondering what a dtype is, we hack on that. For more on dtypes, see the appprpriate section in the Numpy reference and the user guide.

%matplotlib inline from matplotlib.pyplot import * from numpy import * x = linspace(2, 8, 4) x
array([ 2., 4., 6., 8.])
type(x)
numpy.ndarray
type(x[0])
numpy.float64
y = [int(x1) for x1 in x] y
[2, 4, 6, 8]
x2 = [int(x1) for x1 in linspace(2, 8, 4)] x2
[2, 4, 6, 8]
x3 = linspace(2,8,4, dtype=int) x3
array([2, 4, 6, 8])
type(x3[0])
numpy.int32
print(type(22)) print(type(int32(22)))
<class 'int'> <class 'numpy.int32'>