Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Inserting Elements into the Array | List and Array
Algorithms and Data Structures Overview

book
Challenge: Inserting Elements into the Array

Завдання

Swipe to start coding

Рішення

import numpy as np
import time
import matplotlib.pyplot as plt

# Define a list of N values
N_values = [1000, 2000, 3000, 4000, 5000]

# Create an empty list to store the time for each N value
times = []

for N in N_values:
np_array = np.array([])
# Measure the start time
array_start = time.process_time()
# Insert random numbers into the array
for _ in range(N):
random_number = np.random.randint(0, 10000)
np_array = np.insert(np_array, 0, random_number)
# Measure the end time
array_end = time.process_time()
# Calculate the time taken
array_time = array_end - array_start
# Append the time to the times list
times.append(array_time)

# Plot the dependency of time on N values
plt.figure(figsize=(8, 6))
plt.plot(N_values, times)
plt.xlabel('N values')
plt.ylabel('Time (seconds)')
plt.title('Dependency of Time on N values')

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 3
import numpy as np
import time
import matplotlib.pyplot as plt

# Define a list of N values
N_values = [1000, 2000, 3000, 4000, 5000]

# Create an empty list to store the time for each N value
times = []

for N in N_values:
np_array = np.array([])
# Measure the start time
array_start = time.process_time()
# Insert random numbers into the array
for _ in range(N):
random_number = np.random.randint(0, 10000)
np_array = np.___(np_array, 0, random_number)
# Measure the end time
array_end = time.process_time()
# Calculate the time taken
array_time = ___ - ___
# Append the time to the times list
times.append(array_time)

# Plot the dependency of time on N values
plt.figure(figsize=(8, 6))
plt.plot(N_values, times)
plt.xlabel('N values')
plt.ylabel('Time (seconds)')
plt.title('Dependency of Time on N values')

Запитати АІ

expand
ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt