nested list space complexity, What is the space complexity of the following: - space-complexity

Is their space complexity the same?
[ [2], [], [3] ]
[ [2,['A','B',2]], [], [3,['A','A',3] ]

Related

What does multi-gpu training in keras really mean?

I want to train LSTMs on multiple GPUs.
After stumpling upon this article: (https://www.pugetsystems.com/labs/hpc/RTX-2080Ti-with-NVLINK---TensorFlow-Performance-Includes-Comparison-with-GTX-1080Ti-RTX-2070-2080-2080Ti-and-Titan-V-1267/#functionality-and-peer-to-peer-data-transfer-performance-for-2-rtx-2080-gpus-with-nvlink)
I found out, that the training speed nearly doubles with a second GPU. But I cant figure out (or maybe overlooked) if the writer uses model parallelism or data parallelism (or something else).
And what performance Increase i can expect from using 2 GPUs. (half the time?)
Extra: if it works like stated above, i wonder wether i can combine 2 different GPUs (without NVLink) like a 3080 & a 3090.
Note: I wont be able to use a NVLink.
EDIT:
#runDOSrun Float or double sequences (of around 1.000-15.000 rows & around 10-100 columns), 1-2M Samples
[ 89.319787 1.329743 99.234670 ... 52.329743 0.319787 2.319787 ]
[ 84.319787 1.329743 49.329743 ... 52.329743 0.319 2.319787 ]
[ 12.319787 1.329743 33.329743 ... 52.329743 0.319787 2.319787 ]
...
[ 84.319787 1.329743 49.329743 ... 52.329743 0.319 2.319787 ]
[ 12.319787 1.329743 33.329743 ... 52.329743 0.319787 2.319787 ]
[ 33.319787 1.329743 23.329743 ... 52.329743 0.319787 2.319787 ] ]
Batch_size 8, 16 or 32 LSTM with these layers [700,700,700,700,64,32] On 2 RTX 3080 or 1x3080+1x3090

How do I create a surface plot with matplotlib of a closed loop revolve about an axis given coordinate data of the 2D profile?

I have the closed loop stored as a two column by N row numpy array.
The last row of the array is the same as the first row, implying that it is, indeed, a closed loop.
The number of angular divisions in the rotation (as in, "slices of pie" so to speak) ought be set by a variable called 'angsteps'
The profile in question is plotted in the x-y coordinate plane, and is rotated about the 'x-axis'.
You can find the profile in question plotted here. https://i.imgur.com/yJoKIEp.png
I apologize for the lack of code, but the profile data has so many interdependencies that I can't post the code that generates it without basically taking a shortcut to plugging the github page for it.
a downsampled version of the curve data looks like this.
bulkmat = [[ 5.2 0. ]
[ 0.381 0. ]
[ 0.381 3.164 ]
[ 2. 3.164 ]
[ 2. 4.1 ]
[ 3.78 4.1 ]
[ 3.78 6.477 ]
[ 1.898 6.477 ]
[ 1.898 7. ]
[ 3.18 7. ]
[ 3.18 9.6 ]
[ 1.898 9.6 ]
[ 1.898 9.6 ]
[ 2.31987929 12.42620027]
[ 3.4801454 15.24663923]
[ 5.22074074 17.97407407]
[ 7.38360768 20.521262 ]
[ 9.81068861 22.80096022]
[ 12.34392593 24.72592593]
[ 14.825262 26.20891632]
[ 17.09663923 27.16268861]
[ 19. 27.5 ]
[ 19. 27.5 ]
[ 19.62962963 27.44718793]
[ 20.18518519 27.29972565]
[ 20.66666667 27.07407407]
[ 21.07407407 26.7866941 ]
[ 21.40740741 26.45404664]
[ 21.66666667 26.09259259]
[ 21.85185185 25.71879287]
[ 21.96296296 25.34910837]
[ 22. 25. ]
[ 22. 25. ]
[ 21.12125862 24.17043472]
[ 18.91060645 23.59946824]
[ 15.97201646 22.9218107 ]
[ 12.84280513 21.85346069]
[ 9.96762011 20.14089993]
[ 7.67242798 17.51028807]
[ 6.13850192 13.61665735]
[ 5.37640942 7.99310742]
[ 5.2 0. ]]
The following would be an example of a solid of revolution plotted around the z axis. As input we take some points and then create the necessary 2D arrays from them.
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d
# input xy coordinates
xy = np.array([[1,0],[2,1],[2,2],[1,1.5],[1,0]])
# radial component is x values of input
r = xy[:,0]
# angular component is one revolution of 60 steps
phi = np.linspace(0, 2*np.pi, 60)
# create grid
R,Phi = np.meshgrid(r,phi)
# transform to cartesian coordinates
X = R*np.cos(Phi)
Y = R*np.sin(Phi)
# Z values are y values, repeated 60 times
Z = np.tile(xy[:,1],len(Y)).reshape(Y.shape)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax2 = fig.add_axes([0.05,0.7,0.15,.2])
ax2.plot(xy[:,0],xy[:,1], color="k")
ax.plot_surface(X, Y, Z, alpha=0.5, color='gold', rstride=1, cstride=1)
plt.show()

How to sort a two-dimensional array in descending order for a column?

array([[ 0. , 0.04],
[ 0. , 0.1 ],
[ 0. , 0.2 ],
[ 0. , 0.4 ],
[ 0.27, 1. ],
[ 0.3 , 1. ]])
How to sort the array by the second column in descend order in an simple way ?
The result's shape is also (6,2).
Get argsort indices for the second column, flip them and index into rows -
a[a[:,1].argsort()[::-1]]
Alternatively, get argsort indices on negated version and index into rows -
a[(-a[:,1]).argsort()]

Line partially not plotted

Problem:
Plotting a closed 2D polygon works fine.
When I try plotting it 1D (by replacing the second dimension with a constant), it fails in some special cases: Then the polygon (which becomes a line) is not drawn completely.
What I tried:
Different plotting-styles like . , o -- of which only the latter one reproduces the problem while non-line-like-styles work.
Shifted/rolled the polygon-array which did not work when shifting by 1 or 2, but for 3 and 4 that solved the problem.
Asked a friend who is clueless ^^
Helped myself so far by directly plotting a line between x.min() and x.max().
For simplicity I removed the z-Data. When plotting x in combination with z, it also works - as long as z is far away from being constant. But then I get a wobbly graph instead of a straight line.
Still How can it be, that whether the data is fully plotted or not depends on its order? What did I do wrong?
I tried reducing the data for one of the special cases, but did not get very far.
Here's the working mini-example to produce the image, I'm sorry for the long dataset but could not figure out which values to remove while keeping the problem reproducable.
import numpy as np
from matplotlib import pyplot as plt
s = np.array([
[-0.08527125, 0.08810856],
[-0.08967261, -0.06748633],
[-0.08772675, -0.08396971],
[-0.08766724, -0.08440267],
[-0.08748191, -0.08521958],
[-0.08438602, -0.09529874],
[-0.08385044, -0.09684308],
[-0.08202714, -0.10180355],
[-0.07874478, -0.1066276 ],
[-0.07857811, -0.10686354],
[-0.07789635, -0.10778213],
[-0.07781094, -0.10789337],
[-0.07710836, -0.10880646],
[-0.07007289, -0.11655674],
[-0.06962708, -0.11703841],
[-0.06727917, -0.11933749],
[-0.06584873, -0.12070607],
[-0.06552574, -0.12100522],
[-0.06527846, -0.12121293],
[-0.06401669, -0.12214381],
[-0.06349801, -0.12245992],
[-0.06328962, -0.12258028],
[-0.0627093 , -0.12290901],
[-0.06225359, -0.12314782],
[-0.06116991, -0.12368258],
[-0.06041895, -0.12403051],
[-0.06017477, -0.12413955],
[-0.05992829, -0.12424804],
[-0.04659197, -0.13006904],
[-0.04634663, -0.13017319],
[-0.04628731, -0.1301966 ],
[-0.04567821, -0.13041967],
[-0.04552972, -0.13047215],
[-0.04521702, -0.13058213],
[-0.00325617, -0.14513102],
[ 0.00180445, -0.14683444],
[ 0.00950078, -0.14923653],
[ 0.01392647, -0.15030046],
[ 0.01518804, -0.15045976],
[ 0.02734024, -0.15177574],
[ 0.02813995, -0.15177997],
[ 0.02882764, -0.15176844],
[ 0.02947446, -0.15171012],
[ 0.03001744, -0.15165147],
[ 0.0309922 , -0.15149313],
[ 0.03121784, -0.15145567],
[ 0.031327 , -0.15143527],
[ 0.03142507, -0.15141573],
[ 0.03150791, -0.15139799],
[ 0.03222764, -0.15124224],
[ 0.03798838, -0.14988557],
[ 0.038991 , -0.1496481 ],
[ 0.0391266 , -0.14961472],
[ 0.03920601, -0.14959498],
[ 0.03938681, -0.14954736],
[ 0.03991586, -0.14940614],
[ 0.05465674, -0.14538513],
[ 0.05500815, -0.14528457],
[ 0.05512499, -0.14524203],
[ 0.05522656, -0.14520209],
[ 0.05558739, -0.14504381],
[ 0.05580602, -0.1449474 ],
[ 0.05609256, -0.14478439],
[ 0.05713959, -0.14412759],
[ 0.05743526, -0.14392656],
[ 0.05889567, -0.14277855],
[ 0.06059875, -0.14143159],
[ 0.06530732, -0.13766523],
[ 0.06933674, -0.13424303],
[ 0.0702827 , -0.13335664],
[ 0.07036637, -0.13327235],
[ 0.07405533, -0.12951652],
[ 0.07810863, -0.125367 ],
[ 0.08087981, -0.12226141],
[ 0.08176499, -0.12123622],
[ 0.08381519, -0.1150717 ],
[ 0.08734418, -0.0927558 ],
[ 0.08230393, 0.09131774],
[ 0.08183173, 0.097691 ],
[ 0.08169106, 0.09931977],
[ 0.08130204, 0.10177584],
[ 0.07914312, 0.11230088],
[ 0.07895476, 0.11316267],
[ 0.07514703, 0.12076318],
[ 0.07464758, 0.12166996],
[ 0.0733333 , 0.12382546],
[ 0.07297538, 0.12425848],
[ 0.06620658, 0.13199037],
[ 0.05294461, 0.14660768],
[ 0.05262742, 0.14694802],
[ 0.05097036, 0.14849098],
[ 0.04972845, 0.14937964],
[ 0.04815287, 0.15002114],
[ 0.04783434, 0.15013311],
[ 0.04757239, 0.15022502],
[ 0.02928349, 0.15634586],
[ 0.02842644, 0.15662035],
[ 0.02776939, 0.15677726],
[ 0.0270936 , 0.15690821],
[ 0.02666639, 0.15698384],
[ 0.02610376, 0.15707915],
[ 0.02601474, 0.15709266],
[ 0.025126 , 0.15722434],
[ 0.02474755, 0.15727606],
[ 0.02296123, 0.15742128],
[ 0.02202472, 0.15744494],
[ 0.02086636, 0.15744469],
[ 0.01967163, 0.15742308],
[ 0.01872141, 0.15737815],
[ 0.01568162, 0.15718458],
[-0.00722516, 0.15361993],
[-0.00785781, 0.15350418],
[-0.02865655, 0.14966376],
[-0.02928172, 0.1495445 ],
[-0.02970399, 0.14942282],
[-0.03124785, 0.14896281],
[-0.03160079, 0.14884731],
[-0.03311488, 0.14832349],
[-0.04643741, 0.14369722],
[-0.04831254, 0.14301643],
[-0.04846789, 0.14294296],
[-0.04902343, 0.14264339],
[-0.04980039, 0.14218488],
[-0.05127431, 0.14122099],
[-0.05343824, 0.13978482],
[-0.06641953, 0.1306598 ],
[-0.06719992, 0.13009146],
[-0.06732267, 0.12997761],
[-0.06842394, 0.12872382],
[-0.06895024, 0.12808815],
[-0.07854825, 0.11574519],
[-0.08365013, 0.10504 ],
[-0.0837306 , 0.10486896],
[-0.08384365, 0.10417084],
[-0.08444646, 0.09768441]])
# make first and last point the same, to close the circle
s = np.concatenate([s,s[:1]])
y = s[:,0]
x = s[:,1]
# plot the polygon xy
plt.plot(x, y, 'b--', label='Polygon with x/y')
# plot only x values of the polygon (does not work)
plt.plot(x, np.zeros(len(x)), 'g-', linewidth=10, label='does not stretch over red dots')
# do the same, but with dots to show x values (does work)
plt.plot(x, np.zeros(len(x)), 'r.')
# do the same, a little bit lower, but with shifted/rolled x values.
# rolled by 1 or 2 does not help, but by 3 or 4 does.
plt.plot(np.roll(x,3), np.ones(len(x))-1.02, '-', color="lightgreen", linewidth=10, label="stretches over red dots")
# do the same again with dots to show x values
plt.plot(np.roll(x,3), np.ones(len(x))-1.02, 'r.')
plt.legend(loc='lower center').get_frame().set_alpha(1)
plt.show()
Python 3.5 x64 via Anaconda in Windows10. Matplotlib is v2.0.0
How long is a swimming pool that is 0 mm wide? In theory, it has a length of course, but in practice you couldn't measure it. The same happens here, a polygon without extention in one dimension could potentially be rendered to any length. And you would see the same effect happening to both polygons depending on the figure size, zoom level, axis range.
I think you already found a solution, by plotting a line instead of a polygon. And that would also be my recommendation.

transposing data in array using numpy

I have list as following and need to be tranposed to a numpy array
samplelist= [ [ ['Name-1','Name-2','Name-3'] , ['Age-1','Age-2','Age-3'] ],
[ ['new_Name_1','new_Name_2','new_Name_3'], ['new_Age_1','new_Age_2','new_Age_3'] ]
]
Expected Result:
samplearray = [ [ ['Name-1','Age-1'], ['Name-2','Age-2'], ['Name-3','Age-3'] ],
[ ['new_Name_1','new_Age_1], ['new_Name_2','new_Age_2'], ['new_Name_3','new_Age_3'] ]
]
np.transpose results:
np.transpose(a)
array([[['Name-1', 'new_Name_1'],
['Age-1', 'new_Age_1']],
[['Name-2', 'new_Name_2'],
['Age-2', 'new_Age_2']],
[['Name-3', 'new_Name_3'],
['Age-3', 'new_Age_3']]],
dtype='|S10')
samplelist is a 3-D array.
In [58]: samplelist.shape
Out[58]: (2, 2, 3)
Using transpose swaps the first and last axes (0 and 2):
In [55]: samplelist.T
Out[55]:
array([[['Name-1', 'new_Name_1'],
['Age-1', 'new_Age_1']],
[['Name-2', 'new_Name_2'],
['Age-2', 'new_Age_2']],
[['Name-3', 'new_Name_3'],
['Age-3', 'new_Age_3']]],
dtype='|S10')
In [57]: samplelist.swapaxes(0,2)
Out[57]:
array([[['Name-1', 'new_Name_1'],
['Age-1', 'new_Age_1']],
[['Name-2', 'new_Name_2'],
['Age-2', 'new_Age_2']],
[['Name-3', 'new_Name_3'],
['Age-3', 'new_Age_3']]],
dtype='|S10')
To get the desired array, swap axes 1 and 2:
import numpy as np
samplelist = np.array([
[ ['Name-1','Name-2','Name-3'] , ['Age-1','Age-2','Age-3'] ],
[ ['new_Name_1','new_Name_2','new_Name_3'], ['new_Age_1','new_Age_2','new_Age_3'] ]
])
print(samplelist.swapaxes(1,2))
# [[['Name-1' 'Age-1']
# ['Name-2' 'Age-2']
# ['Name-3' 'Age-3']]
# [['new_Name_1' 'new_Age_1']
# ['new_Name_2' 'new_Age_2']
# ['new_Name_3' 'new_Age_3']]]