AITC Wiki

numpy1

NumPy 复习 1

numpy1

中文版:NumPy 复习 1

some examples for Numpy 1

  1. always import the package first!
import numpy
import numpy as np
  1. create variables (array) which can be used in Numpy.
# create from list 1
l=[1,2,3]
a=np.array(l)
print("l=",l,type(l))
print("a=",a,type(a))
# create from list 2
b=np.array([1,2,3])
print("b=",b,type(b))
# create from list 3
c=np.array([[1,2,3]])
print("c=",c,type(c)) #what is the difference between b and c? 1D array or 2D array
# create from list 4
d=np.array([[1,2,3],[4,5,6]])
print(d)
# create from list 5
e=np.array([[[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]]])
print(e) # what is the dimension of e?

practice 1

  1. create two arrays:

and

fix the errors:

import(numpy)
import Numpy
import Numpy NP
import numpy as np
l=NP.array([1])
print(l)
l=numpy.aray([2,2])
l=ny. array([[1],[1]])
l=ny.array([[1,2,3],[4,5,6])