<jupyter_start><jupyter_text>numpy的数组切片实质返回的是指针/引用，而不是值的拷贝<jupyter_code>x2_sub = x2[:2,:2]
x2_sub
x2_sub[0,0] = 99
x2_sub
x2<jupyter_output><empty_output><jupyter_text>必须使用copy()方法才能拷贝值<jupyter_code>x2_sub_copy = x2_sub.copy()
x2_sub_copy
x2_sub_copy[0,0] = -100
x2_sub_copy
x2
x2.reshape(1,12)<jupyter_output><empty_output><jupyter_text>数组的拼接<jupyter_code>x = np.array([1,2,3])
y = np.array([3,2,1])
z = np.array([4,5,6])
print(np.concatenate([x,y,z]))
print(np.concatenate([[x],[y],[z]]))
grid = np.array([[1,2,3],[4,5,6]])
np.hstack([grid,grid])
np.vstack([grid,grid])
np.dstack([grid,grid])<jupyter_output><empty_output><jupyter_text>数组的分裂<jupyter_code>x = [1,2,3,99,99,3,2,1]
x1,x2,x3 = np.split(x,[3,5])
print(x1,x2,x3)
np.arange(5) / np.arange(1,6)
big_array = np.random.random(1000000)
%timeit sum(big_array)
%timeit np.sum(big_array)<jupyter_output>139 ms ± 545 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
997 µs ± 6.09 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)<jupyter_text>K个临近点<jupyter_code>x = np.random.random([10,2])
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn
seaborn.set()
plt.scatter(x[:,0],x[:,1],s=100)
dist_sq = np.sum((x[:,np.newaxis,:]-x[np.newaxis,:,:]) ** 2, axis = -1)
dist_sq.shape
dist_sq.diagonal()
nearest = np.argsort(dist_sq,axis=1)
print(nearest)
k = 2
nearest_partition = np.argpartition(dist_sq,k+1,axis=1)
plt.scatter(x[:,0],x[:,1],s=100)
for i in range(x.shape[0]):
    for j in  nearest_partition[i, :k+1]:
        plt.plot(*(zip(x[j],x[i])),color='red')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20610687022900764, 'fraction_numerical': 0.07061068702290077, 'mean_word_length': 7.69060773480663, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '235352', 'license': 'MIT', 'n_tokens_mistral': 842, 'n_tokens_neox': 809, 'n_words': 107, 'path': '11.6.ipynb', 'repo_name': 'Dante-code/python-data-science-handbook', 'size': '1572'}