This time to bring you how to numpy in the array elements to unify the value of the array elements in the NumPy to assign a unified value of the attention to the matter, the following is the actual case, to see together.
Array integer handling assignment in NumPy I'm a little confused, a lot of times I don't understand. Write a separate list of relevant knowledge points today and summarize them.
Let's look at two code slices for a small example:
Example 1:
In [2]: Arr =np.empty ((8,4)) in [3]: Arrout[3]:array ([[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0. ], [0., 0., 0., 0. ], [0., 0., 0., 0.], [0., 0., 0., 0.]] In [4]: arr[1] = 1In [5]: Arrout[5]:array ([[0., 0., 0., 0.], [1., 1., 1., 1. ], [0., 0., 0., 0.], [0., 0 ., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0. ], [0., 0., 0., 0. ], [0., 0., 0., 0.]
Example 2:
In [6]: arr1 =np.empty (2) in [8]: Arr1out[8]:array ([7.74860419e-304, 7.74860419e-304]) in [9]: arr1 = 0In [ten]: Arr1out [10]: 0
These two paragraphs seem to appear to be inconsistent behavior, in fact, the use of generic object-oriented tags to understand the model is still understandable.
In Example 1, the label after the index actually refers to the specific storage area, and Example 2, the direct use of a tag. So how do you implement the entire assignment of a one-dimensional array? In fact, you just need to index all the elements,
The specific method is implemented as follows:
In [all]: arr1 =np.empty (2) in []: arr1out[12]: Array ([0., 0.]) in [+]: arr1[:]out[13]: Array ([0., 0.]) In []: arr1[:] =0in []: arr1out[15]: Array ([0., 0.])
It seems pretty simple, but without a bit of a bit of analysis, it really is a little bit more difficult to understand.
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
Python NumPy How to manipulate arrays and matrices
How the python numpy array is merged