Constructor
(numpy.)
Description
Example
array(data,
dtype)
Creates a numeric array object from another
array or array-like data. All values will be
converted to the same data type. Data type will
be inferred from the input values if not
specifically stated. An array may have more
than one dimension/axis, e.g. constructed using
a list of lists.
a = array([[1,
2, 3],
[4, 5, 6]])
a.shape #
(2,3) – rows,
cols
a.ndim # 2 -
axes
a.tolist() #
Make Python
list
b =
array([3.0, 0,
4.7, 1],
float)
# Floats: 3.0,
0.0, 4.7, 1.0
matrix(data,
dtype)
Creates a numeric matrix object from an array
or array-like data. Provides an alternative to
array() that has more matrix-oriented
operations, e.g. multiplication is not element-
wise. Data type will be inferred from the input
values if not specifically stated.
m1 =
matrix([[1,2],
[1,0]])
m2 =
matrix([[3,0],
[0,3]])
print(m1 * m2)
# matrix([[3,
6],
#
[3, 0]])
Do'stlaringiz bilan baham: |