“insert numpy” Kode Jawaban

Tambahkan Numpy

>>> np.add(1.0, 4.0)
5.0
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.add(x1, x2)
array([[  0.,   2.,   4.],
       [  3.,   5.,   7.],
       [  6.,   8.,  10.]])
Curious Cockroach

Python numpy insert function sintaks

numpy.insert(array, object, values, axis = None)
Outrageous Ostrich

insert numpy

b = a.flatten()
>>> b
array([1, 1, 2, 2, 3, 3])
>>> np.insert(b, [2, 2], [5, 6])
array([1, 1, 5, ..., 2, 3, 3])
Krystian P.

Python Numpy Insert Function Contoh Bekerja dengan Array

# welcome to softhunt.net
# Python Program illustrating
# numpy.insert()

import numpy as np

#Working on 1D
arr = np.arange(5)
print("1D arr : \n", arr)
print("Shape : ", arr.shape)

# value = 9
# index = 1
# Insertion before first index
a = np.insert(arr, 1, 9)
print("\nArray after insertion : ", a)
print("Shape : ", a.shape)


# Working on 2D array
arr = np.arange(12).reshape(3, 4)
print("\n\n2D arr : \n", arr)
print("Shape : ", arr.shape)

a = np.insert(arr, 1, 9, axis = 1)
print("\nArray after insertion : \n", a)
print("Shape : ", a.shape)
Outrageous Ostrich

Jawaban yang mirip dengan “insert numpy”

Pertanyaan yang mirip dengan “insert numpy”

Lebih banyak jawaban terkait untuk “insert numpy” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya