Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- X = [0.1, 0.7 , 1, 1.35]
- import numpy as np
- X = map(np.array,[X])
- X = [0.1, 0.5 , 1, 1.5]
- X = ( X[:,None] + X[:] )
- #Результат
- [[ 0.2 0.8 1.1 1.45]
- [ 0.8 1.4 1.7 2.05]
- [ 1.1 1.7 2. 2.35]
- [ 1.45 2.05 2.35 2.7 ]]
- [[ 0.8 1.1 1.45]
- [ 0.8 1.7 2.05]
- [ 1.1 1.7 2.35]
- [ 1.45 2.05 2.35 ]]
- Y = [0.3, 0.5, 0.7, 0.9]
- (X[:,None] + X[:]) + (Y[:,None] + Y[:])
- X[:,None] + Y[:]
- def f(array):
- new = [x+y for x in array for y in array if y!=x]
- return new
- print(f([1, 2, 3]))
- [3, 4,
- 3, 5,
- 4, 5]
- def for_stack(array):
- list_for_num_array = []
- for i in array:
- list_for_num_array.append([x+y for x in i for y in i if y!= x])
- return np.array(list_for_num_array)
- X = np.array([[0.1, 0.7 , 1, 1.35]])
- print(for_stack(X[:None]))
- [[ 0.8, 1.1, 1.45,
- 0.8, 1.7, 2.05,
- 1.1, 1.7, 2.35,
- 1.45, 2.05, 2.35]]
- def for_stack(array):
- list_for_num_array = []
- for i in array:
- list_for_num_array.append([j+n for x, j in enumerate(i) for y, n in enumerate(i) if x != y])
- return np.array(list_for_num_array)
- X = np.array([[1, 2, 2], [1, 2, 2]])
- print(for_stack(X[:None]))
- [[3 3 3 4 3 4],
- [3 3 3 4 3 4]]
- def for_stack(array):
- list_for_num_array = []
- try:
- for i, j in enumerate(array):
- list_for_num_array.append([x+n for x, n in zip(array[i], array[i+1])])
- return list_for_num_array
- except IndexError:
- pass
- return np.array(list_for_num_array)
- X = np.array([[0.1, 0.7 , 1, 1.35], [2, 3, 4, 5]])
- print(for_stack(X[:None]))
- [[ 2.1 3.7 5. 6.35]]
- In [221]: X = np.array([0.1, 0.7 , 1, 1.35])
- In [222]: l = len(X)
- In [223]: A = np.delete(X[:,None] + X[:], np.arange(0, l**2, l+1)).reshape(l,l-1)
- In [224]: A
- Out[224]:
- array([[ 0.8 , 1.1 , 1.45],
- [ 0.8 , 1.7 , 2.05],
- [ 1.1 , 1.7 , 2.35],
- [ 1.45, 2.05, 2.35]])
- In [225]: A.sum(axis=1)
- Out[225]: array([ 3.35, 4.55, 5.15, 5.85])
- In [228]: np.delete(X[:,None] + X[:], 5)
- Out[228]: array([ 0.2 , 0.8 , 1.1 , 1.45, 0.8 , 1.7 , 2.05, 1.1 , 1.7 , 2. , 2.35, 1.45, 2.05, 2.35, 2.7 ])
- In [229]: np.arange(0, l**2, l+1)
- Out[229]: array([ 0, 5, 10, 15])
- In [230]: np.delete(X[:,None] + X[:], np.arange(0, l**2, l+1))
- Out[230]: array([ 0.8 , 1.1 , 1.45, 0.8 , 1.7 , 2.05, 1.1 , 1.7 , 2.35, 1.45, 2.05, 2.35])
- In [231]: np.delete(X[:,None] + X[:], np.arange(0, l**2, l+1)).reshape(l,l-1)
- Out[231]:
- array([[ 0.8 , 1.1 , 1.45],
- [ 0.8 , 1.7 , 2.05],
- [ 1.1 , 1.7 , 2.35],
- [ 1.45, 2.05, 2.35]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement