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 xIter = this.xData.getIndexIterator();
IndexIterator yIter = this.yData.getIndexIterator(); IndexIterator yIter = this.yData.getIndexIterator();
double x, y; double x, y;
while (xIter.hasNext()) { while (xIter.hasNext() && yIter.hasNext()) {
x = xIter.getDoubleNext(); x = xIter.getDoubleNext();
y = yIter.getDoubleNext(); y = yIter.getDoubleNext();
if (Double.isNaN(x) || Double.isNaN(y)) { if (Double.isNaN(x) || Double.isNaN(y)) {

View File

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

View File

@ -1285,24 +1285,38 @@ class NDArray(object):
""" """
self.flat[:] = value self.flat[:] = value
def flatten(self): def flatten(self, order='C'):
""" """
Return a copy of the array collapsed into one dimension. 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. :returns: (*NDArray*) A copy of the input array, flattened to one dimension.
""" """
shape = [self.size] shape = [self.size]
if order.upper() == 'C':
r = NDArray(self._array.reshape(shape)) r = NDArray(self._array.reshape(shape))
else:
r = self.swapaxes(-1, -2)
r = NDArray(r._array.reshape(shape))
return r return r
def ravel(self): def ravel(self, order='C'):
""" """
Return a contiguous flattened array. 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. :returns: (*NDArray*) A contiguous flattened array.
""" """
shape = [self.size] shape = [self.size]
if order.upper() == 'C':
r = NDArray(self._array.reshapeNoCopy(shape)) r = NDArray(self._array.reshapeNoCopy(shape))
else:
r = self.swapaxes(-1, -2)
r = NDArray(r._array.reshape(shape))
return r return r
def repeat(self, repeats, axis=None): def repeat(self, repeats, axis=None):

View File

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