update flatten and ravel functions

This commit is contained in:
wyq 2024-08-26 21:05:38 +08:00
parent e207d3821a
commit d0f556f076
4 changed files with 35 additions and 17 deletions

View File

@ -76,7 +76,7 @@ public class Line2DGraphic extends Graphic {
IndexIterator xIter = this.xData.getIndexIterator();
IndexIterator yIter = this.yData.getIndexIterator();
double x, y;
while (xIter.hasNext()) {
while (xIter.hasNext() && yIter.hasNext()) {
x = xIter.getDoubleNext();
y = yIter.getDoubleNext();
if (Double.isNaN(x) || Double.isNaN(y)) {

View File

@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<MeteoInfo File="milconfig.xml" Type="configurefile">
<Path OpenPath="D:\Working\MIScript\Jython\mis\map\webmap">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\surf"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar\cinrad"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\contour"/>
<Path OpenPath="D:\Working\MIScript\Jython\mis\plot_types\plot">
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\chart\legend"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\imshow"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\radar"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\dataconvert"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grib"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\map\webmap"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\funny"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\animation"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types"/>
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\plot"/>
</Path>
<File>
<OpenedFiles>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_2d.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\plot_cuace_3d_slice.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\map\webmap\webmap_4.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\ghost_halloween.py"/>
<OpenedFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\math_man.py"/>
</OpenedFiles>
<RecentFiles>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\slice_2d.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\slice\plot_cuace_3d_slice.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\map\webmap\webmap_4.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\ghost_halloween.py"/>
<RecentFile File="D:\Working\MIScript\Jython\mis\plot_types\funny\math_man.py"/>
</RecentFiles>
</File>
<Font>
@ -34,5 +34,5 @@
</Font>
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
<Figure DoubleBuffering="true"/>
<Startup MainFormLocation="-7,0" MainFormSize="1361,832"/>
<Startup MainFormLocation="-7,-7" MainFormSize="1293,765"/>
</MeteoInfo>

View File

@ -1285,24 +1285,38 @@ class NDArray(object):
"""
self.flat[:] = value
def flatten(self):
def flatten(self, order='C'):
"""
Return a copy of the array collapsed into one dimension.
:param order: (*str*) Optional. ['C' | 'F'], C means to flatten in row-major (C-style) order.
F means to flatten in column-major (Fortran- style) order. The default is C.
:returns: (*NDArray*) A copy of the input array, flattened to one dimension.
"""
shape = [self.size]
r = NDArray(self._array.reshape(shape))
if order.upper() == 'C':
r = NDArray(self._array.reshape(shape))
else:
r = self.swapaxes(-1, -2)
r = NDArray(r._array.reshape(shape))
return r
def ravel(self):
def ravel(self, order='C'):
"""
Return a contiguous flattened array.
:param order: (*str*) Optional. ['C' | 'F'], C means to flatten in row-major (C-style) order.
F means to flatten in column-major (Fortran- style) order. The default is C.
:returns: (*NDArray*) A contiguous flattened array.
"""
shape = [self.size]
r = NDArray(self._array.reshapeNoCopy(shape))
if order.upper() == 'C':
r = NDArray(self._array.reshapeNoCopy(shape))
else:
r = self.swapaxes(-1, -2)
r = NDArray(r._array.reshape(shape))
return r
def repeat(self, repeats, axis=None):

View File

@ -68,6 +68,7 @@ class Line2D(Line2DGraphic, Artist):
:param xdata: (*array*) The xdata.
"""
xdata = np.asarray(xdata)
self._x = xdata
self.setXData(xdata._array)
self.stale = True
@ -88,6 +89,7 @@ class Line2D(Line2DGraphic, Artist):
:param ydata: (*array*) The ydata.
"""
ydata = np.asarray(ydata)
self._y = ydata
self.setYData(ydata._array)
self.stale = True
@ -125,6 +127,8 @@ class Line2D(Line2DGraphic, Artist):
xdata = args[0]
ydata = args[1]
xdata = np.asarray(xdata)
ydata = np.asarray(ydata)
self._x = xdata
self._y = ydata
self.setData(xdata._array, ydata._array)