ArmRoundMan

博客园 首页 新随笔 联系 订阅 管理

Python calls matrices lists, NumPy calls them arrays and TensorFlow calls them tensors. Python represents matrices with the list data type.

  • Call np.array to create a NumPy array with your own hand-picked values. For example, the following call creates a 3x2 array:
1 two_dimensional_array = np.array([[6, 5], [11, 7], [4, 8]])
2 print(two_dimensional_array)
View Code
  • To populate an array with all zeroes or ones, call np.zeros. To populate an array with all , call np.ones.
  • To populate an array with a sequence of numbers:
1 sequence_of_integers = np.arange(5, 12)
View Code

Note that the upper bound of theargument is not generated.

  • To populate a 6-element array with random integers between 50 and 100
1 random_integers_between_50_and_100 = np.random.randint(low=50, high=101, size=(6,))

Note that the highest possibly generated integer of np.random.randint is one less than the high argument.

  • To create random floating-point values between 0.0 and 1.0,
random_floats_between_0_and_1 = np.random.random((6,))
View Code

 Note that  np.random.random((6,))  is equal to  np.random.random([6]) .

posted on 2024-08-22 20:07  后生那各膊客圆了  阅读(2)  评论(0编辑  收藏  举报