Np expand_dims | Numpy expand_dims() Contoh dengan Python #python #numpy #np #programming Numpy expand_dims() memperluas bentuk array. np expand_dims menyisipkan sumbu baru yang akan muncul pada posisi sumbu dalam bentuk array yang diperluas. View Discussion Improve Article Save Article View Discussion Improve Article Save Article With the help of
Example #1 :
Output :
Example #2 :
Output :
Expand the shape of an array. Insert a new axis that will appear at the axis position in the expanded array shape. Parametersaarray_likeInput array. axisint or tuple of intsPosition in the expanded axes where the new axis (or axes) is placed. Deprecated since version 1.13.0: Passing an axis where Changed in version 1.18.0: A tuple of
axes is now supported. Out of range axes as described above are now forbidden and raise an View of a with the number of dimensions increased. Examples >>> x = np.array([1, 2]) >>> x.shape (2,) The following is equivalent to >>> y = np.expand_dims(x, axis=0) >>> y array([[1, 2]]) >>> y.shape (1, 2) The following is equivalent to >>> y = np.expand_dims(x, axis=1) >>> y array([[1], [2]]) >>> y.shape (2, 1)
>>> y = np.expand_dims(x, axis=(0, 1)) >>> y array([[[1, 2]]]) >>> y = np.expand_dims(x, axis=(2, 0)) >>> y array([[[1], [2]]]) Note that some examples may use >>> np.newaxis is None True |