SharedLinspace_Experiments.ipynbOpen in CoCalc
Author: John Lockwood
Views : 10
Description: Jupyter notebook Linspace_Experiments.ipynb

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.

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