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:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 two_dimensional_array = np.array([[6, 5], [11, 7], [4, 8]]) 2 print(two_dimensional_array)
- To populate an array with all zeroes or ones, call
np.zeros
. To populate an array with all , callnp.ones
. - To populate an array with a sequence of numbers:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 sequence_of_integers = np.arange(5, 12)
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,
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
random_floats_between_0_and_1 = np.random.random((6,))
Note that np.random.random((6,)) is equal to np.random.random([6]) .