糖粟与秋泊

文章 评论 浏览 27

糖粟与秋泊 2025-01-27 05:53:15

首先,您已经可以将其视为一个列表,根本不需要转换它,您可以迭代它或执行您可以使用列表执行的所有操作。

但如果你真的想要一个列表,你所要做的就是将它传递到列表构造函数中:

>>> m = np.zeros((30,100,28,28))
>>> m.shape
(30,100,28,28)
>>> l = list(m)
>>> type(l[0])
<class 'numpy.ndarray'>
>>> l[0].shape
(100, 28, 28)
>>> len(l)
30

l 是你的拆分列表

First, you can already consider it as a list, without converting it at all, you can iterate through it or do everything you can do with a list.

But if you really want a list, all you have to do is to pass it in the list constructor :

>>> m = np.zeros((30,100,28,28))
>>> m.shape
(30,100,28,28)
>>> l = list(m)
>>> type(l[0])
<class 'numpy.ndarray'>
>>> l[0].shape
(100, 28, 28)
>>> len(l)
30

l is your splitted list

将4D Numpy阵列纳入3D Numpy阵列的列表

糖粟与秋泊 2025-01-26 11:26:04

使用选项equarlicit对范围进行排序

  • ,将迫使您声明所有变量(dim WS为工作表dim source_data as range)。

  • 不建议在一行中声明变量,但是如果您无能为力,则需要正确执行:

     昏暗的lastrow长时间,lastcol,只要我长,num and double
     

    因为在dim lastrow中,lastcol为lastrow被声明为为变体


  • 编写设置WS = Sheets(“详细信息”)sheet不合格,即是指活动工作簿(Active> ActiveWorkworkbook ),您正在查看的工作簿可能是正确的工作簿,或者可能不是。

  • 如果您正在使用的工作表在包含代码的工作簿中,那么您希望通过使用thisworkbook

    来限定它。

      dim WS作为工作表:set ws = thisworkbook.worksheets(“详细信息”)
     

  • 如果 想要以以下方式限定每个工作表:

      dim WB作为工作簿:set wb = workbooks(“ test.xlsx”)
     

    或关闭工作簿,请打开...

      dim WB作为工作簿:set wb = workbooks.open(“ c:\ test \ test \ test.xlsx”)
     

    ...并继续...

      dim WS作为工作表:设置ws = wb.worksheets(“详细信息”)  
     
  • 请注意,在某些情况下,您有使用ActiveWorkBook


  • 编写lastrow = cells(rows.count,2).end(xlup)。合格的IE参考活动表(ActivesHeet),该表可以是工作表详细信息或不可能。


  • 要使它使用以下内容:

      dim WS作为工作表:set ws = thisworkbook.worksheets(“详细信息”)
    昏暗的lastrow为长:lastrow = ws.cells(ws.rows.count,2).end(xlup)。      
     

  • 经验法则是要尽可能频繁地(合理的),即不要让Excel为您决定。
  • 您不会使用.header = xlguess,但是当范围包括标头或xlno时,您将使用Xlyes。在您的特殊情况下,您仅引用数据(ws.range(“ b3:u”&amp; lastrow))ie不包括标题,因此您应该使用xlno
  • 参数有关,尽管足以指定要分类的列中的任何单元格,但我建议指定整列IE而不是b2使用B2:Blastrow2是标题行。

  • 请注意,该排序是按顺序从最后一个添加的排序字段到第一个IE执行的,如果您的情况下,订单为mkcb即,对您来说仍然是错误的。
Option Explicit

Sub ToSortFile()

    Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
    
    Dim ws As Worksheet: Set ws = wb.Worksheets("Details")
    
    Dim LastRow As Long: LastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
    Dim LastCol As Long
    LastCol = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column
    
    Dim srg As Range: Set srg = ws.Range("B2", ws.Cells(LastRow, LastCol))
    
    With ws.Sort
        .SortFields.Clear
        .SortFields.Add Key:=srg.Columns(1), Order:=xlAscending
        .SortFields.Add Key:=srg.Columns(2), Order:=xlAscending
        .SortFields.Add Key:=srg.Columns(10), Order:=xlAscending
        .SortFields.Add Key:=srg.Columns(12), Order:=xlAscending
        .SetRange srg
        .Header = xlYes
        .Apply
    End With

End Sub

Sort a Range

  • Using Option Explicit will force you to declare all variables (Dim ws As Worksheet, Dim source_data As Range).

  • Declaring variables in one line is not recommended but if you can't help it you need to do it properly:

    Dim LastRow As Long, LastCol As Long, i As Long, Num As Double
    

    because in Dim lastRow, LastCol As Long, LastRow is declared As Variant.


  • When you write Set ws = Sheets("Details"), Sheets is not qualified i.e. it refers to the active workbook (ActiveWorkbook), the workbook you're looking at which may be the correct workbook or it may not.

  • If the worksheet you're working with is in the workbook containing the code, then you want to qualify it by using ThisWorkbook:

    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Details")
    
  • If it is not, then you want to qualify each worksheet in the following way:

    Dim wb As Workbook: Set wb = Workbooks("Test.xlsx")
    

    or if the workbook is closed, to open it ...

    Dim wb As Workbook: Set wb = Workbooks.Open("C:\Test\Test.xlsx")
    

    ... and continue with...

    Dim ws As Worksheet: Set ws = wb.Worksheets("Details")  
    
  • Note that there are cases when you have to use ActiveWorkbook.


  • When you write lastRow = Cells(Rows.Count, 2).End(xlUp).Row, Cells and Rows are not qualified i.e. they refer to the active sheet (ActiveSheet) which may be worksheet Details or it may not.

  • To qualify it you can use the following:

    Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Details")
    Dim LastRow As Long: LastRow = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row      
    

  • A rule of thumb is to be explicit as often as possible (reasonable) i.e. don't let Excel decide for you.
  • You won't use .Header = xlGuess but you will use xlYes when the range includes the headers or xlNo when it doesn't. In your particular case, you were referencing only the data (Ws.Range("B3:U" & lastRow)) i.e. it didn't include the headers so you should have used xlNo.
  • Related to the Keys argument, although it is enough to specify any cell within the column to be sorted, I would recommend specifying the whole column i.e. instead of B2 use B2:BLastRow, 2 being the header row.

  • Note that the sorting is performed in the order from the last added sort field to the first i.e. in your case the order is M, K, C, and B i.e. it still could be wrong for you.
Option Explicit

Sub ToSortFile()

    Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
    
    Dim ws As Worksheet: Set ws = wb.Worksheets("Details")
    
    Dim LastRow As Long: LastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
    Dim LastCol As Long
    LastCol = ws.Cells(2, ws.Columns.Count).End(xlToLeft).Column
    
    Dim srg As Range: Set srg = ws.Range("B2", ws.Cells(LastRow, LastCol))
    
    With ws.Sort
        .SortFields.Clear
        .SortFields.Add Key:=srg.Columns(1), Order:=xlAscending
        .SortFields.Add Key:=srg.Columns(2), Order:=xlAscending
        .SortFields.Add Key:=srg.Columns(10), Order:=xlAscending
        .SortFields.Add Key:=srg.Columns(12), Order:=xlAscending
        .SetRange srg
        .Header = xlYes
        .Apply
    End With

End Sub

对Excel文件的4个键进行排序

糖粟与秋泊 2025-01-26 10:31:15

您可以尝试以下操作:

val = df['B'].apply(len).max()
cols = ['B'+str(i) if i != 0 else 'B' for i in range(val)]
df[cols] = df['B'].apply(pd.Series).fillna('')

[1]: https://i.sstatic.net/I86pE.png

You can try this:

val = df['B'].apply(len).max()
cols = ['B'+str(i) if i != 0 else 'B' for i in range(val)]
df[cols] = df['B'].apply(pd.Series).fillna('')

[1]: https://i.sstatic.net/I86pE.png

如何将包含列表的数据框单元格拆分为列?

糖粟与秋泊 2025-01-26 09:19:11

使用&lt; packagename&gt; _dir变量指向配置文件的位置。它适用于配置文件随附的任何库。
For you it would look like this:

set(OpenCV_DIR "C:/opencv/build")

Since it is incorrect to add hard-coded paths into persistent scripts, you can choose among different methods of providing this variable to your script:

  • Console invocation: cmake OpenCV_DIR="C:/opencv /build"
  • CMake presets ( user)
  • Local config by using some LocalConfig.cmake with the content above (set(...)), which you include in your main script like this: 包括(localconfig.cmake)

Use <PackageName>_DIR variable pointing to where the config file is located. It works for any library which comes with a config file.
For you it would look like this:

set(OpenCV_DIR "C:/opencv/build")

Since it is incorrect to add hard-coded paths into persistent scripts, you can choose among different methods of providing this variable to your script:

  • Console invocation: cmake OpenCV_DIR="C:/opencv/build"
  • CMake presets (user)
  • Local config by using some LocalConfig.cmake with the content above (set(...)), which you include in your main script like this: include(LocalConfig.cmake)

如何在 CMakeLists.txt 中包含非 Vcpkg?

糖粟与秋泊 2025-01-26 07:08:44

首先导航到清单所在的目录。然后使用以下代码:
az 部署组创建 --resource-group learnStorage1 --template-file azuredeploy.json

First navigate to the directory where the manifest is present.Then use the below code:
az deployment group create --resource-group learnStorage1 --template-file azuredeploy.json

Errno 2 没有这样的文件或目录:“azuredeploy.json”

糖粟与秋泊 2025-01-26 06:31:02

乍一看,WPF 和绑定的一切似乎都很好,但是数据..如果我得到它,这些数据是假的...

      Const **c1** = new Const("ABL", null);
      Const c2 = new Const("ASL", null);
      Const *c3* = new Const("BBL", **c1**);
...
      **c1**.setChildren(new List<Const> { *c3* });

这不是树,因为它有循环,这是你的意图吗?
AFAK 层次结构是关于树而不是图形,这可以永远展开,或者至少它真正有什么意义。

尝试一下测试数据中没有循环的情况

Everything seems fine from WPF and binding at first glance but the data.. which are fake if I get it...

      Const **c1** = new Const("ABL", null);
      Const c2 = new Const("ASL", null);
      Const *c3* = new Const("BBL", **c1**);
...
      **c1**.setChildren(new List<Const> { *c3* });

this is not tree as it has cycles, was this your intention?
AFAK Hierarchical structures are about trees not graph, this can unfold for eternity or at least what meaning does it really have.

give a try without cycles in your test data

使用一个 Model 类将数据绑定到 WPF 中的 TreeView

糖粟与秋泊 2025-01-26 03:20:37

如果您从TCP套接字中读取已知大小的记录数据,并且您知道下一个记录将为250字节,则可能需要调用recv(),大小为250个字节,并使用<<代码> MSG_WAITALL 标志,以确保您读取整个记录或根本没有记录。没有该标志,您只能读取记录的一半,或者仅读取记录的前10个字节。使用该标志,您将始终获得完整的记录或错误(所有其他情况下,您仍然可以较少会导致错误,并且可以完全避免或意味着您永远不会得到完整的记录)。

If you read data in records of known sizes from a TCP socket and you know that the next record will be 250 bytes, you may want to call recv() with a size of 250 bytes and use the MSG_WAITALL flag to ensure you either read the entire record or no record at all. Without that flag you may only read half of a record or only the first 10 bytes of a record. With that flag you will always get a full record or an error (all the other cases where you could still get less result in an error and can either be avoided entirely or mean that you will never get that full record ever).

为什么需要使用`msg_waitall`标志而不是`0`标志?为什么要与UDP一起使用?

糖粟与秋泊 2025-01-26 02:08:34

您可以将多个处理程序附加到记录仪上。

这意味着您可以连接到记录器:

  • 一个fileHandler将以 extims empection 级别(例如警告)登录事件(警告)
  • 一个rotatingfilehandler 记录所有事件(例如或以上的信息或调试)

将使用此类配置 ,第二处理程序将记录所有事件,也记录第一个事件。如果这是一个问题,则可以向第二个滤镜添加一个过滤器,以拒绝在您的重要级别上具有级别的事件。

You can attach more than one handler to a logger.

That means that you could attach to your logger:

  • one FileHandler that will log event at or above the important level (say WARNING)
  • one RotatingFileHandler that will log all events (say at or above INFO or DEBUG)

With such a config, the second handler would log all events also logged by the first one. If this is a problem, you could add a filter to that second one to reject events having a level at (or above) your important level.

在同一个 python 进程上创建 2 个记录器

糖粟与秋泊 2025-01-26 00:42:45

我以非常简单的方式使用了 fuzzywuzz,同时匹配了 pandasmerge 的现有行为和关键字。

只需指定您接受的匹配阈值(在0100之间):

from fuzzywuzzy import process

def fuzzy_merge(df, df2, on=None, left_on=None, right_on=None, how='inner', threshold=80):
    
    def fuzzy_apply(x, df, column, threshold=threshold):
        if type(x)!=str:
            return None
        
        match, score, *_ = process.extract(x, df[column], limit=1)[0]
            
        if score >= threshold:
            return match

        else:
            return None
    
    if on is not None:
        left_on = on
        right_on = on

    # create temp column as the best fuzzy match (or None!)
    df2['tmp'] = df2[right_on].apply(
        fuzzy_apply, 
        df=df, 
        column=left_on, 
        threshold=threshold
    )

    merged_df = df.merge(df2, how=how, left_on=left_on, right_on='tmp')
    
    del merged_df['tmp']
    
    return merged_df

使用示例数据尝试一下:

df1 = pd.DataFrame({'Key':['Apple', 'Banana', 'Orange', 'Strawberry']})

df2 = pd.DataFrame({'Key':['Aple', 'Mango', 'Orag', 'Straw', 'Bannanna', 'Berry']})

fuzzy_merge(df, df2, on='Key', threshold=80)

I have used fuzzywuzz in a very minimal way whilst matching the existing behaviour and keywords of merge in pandas.

Just specify your accepted threshold for matching (between 0 and 100):

from fuzzywuzzy import process

def fuzzy_merge(df, df2, on=None, left_on=None, right_on=None, how='inner', threshold=80):
    
    def fuzzy_apply(x, df, column, threshold=threshold):
        if type(x)!=str:
            return None
        
        match, score, *_ = process.extract(x, df[column], limit=1)[0]
            
        if score >= threshold:
            return match

        else:
            return None
    
    if on is not None:
        left_on = on
        right_on = on

    # create temp column as the best fuzzy match (or None!)
    df2['tmp'] = df2[right_on].apply(
        fuzzy_apply, 
        df=df, 
        column=left_on, 
        threshold=threshold
    )

    merged_df = df.merge(df2, how=how, left_on=left_on, right_on='tmp')
    
    del merged_df['tmp']
    
    return merged_df

Try it out using the example data:

df1 = pd.DataFrame({'Key':['Apple', 'Banana', 'Orange', 'Strawberry']})

df2 = pd.DataFrame({'Key':['Aple', 'Mango', 'Orag', 'Straw', 'Bannanna', 'Berry']})

fuzzy_merge(df, df2, on='Key', threshold=80)

是否可以使用 python pandas 进行模糊匹配合并?

糖粟与秋泊 2025-01-25 16:53:45

==用于测试左侧的值是否等于右侧的值。

=用于将右侧的值分配给左侧的变量。

== is used to test if the value on the left is equal to the value on the right.

= is used to assign the value on the right to the variable on the left.

``=`=='operators'===`是什么区别? (单,双重和三重平等)

糖粟与秋泊 2025-01-25 03:12:06

../ 表示“上一级”。

当您已经处于 / 时,您正在使用它,因此没有级别可以上升。

因此 ../ 被丢弃。

如果您可以制作一个位于服务器根目录之上并访问运行该网站的计算机上的任何文件的 URL,那么这将是一个安全问题。

如果你想访问 JS 文件,那么你需要将它放在有 URL 的地方,然后使用该 URL。

../ means "Go up one level".

You are using it when you are already at / so there isn't a level to go up.

The ../ is therefore discarded.

It would be a security problem if you could craft a URL that would go above the server root and access any files on the computer running the website.

If you want to access the JS file then you will need to put it somewhere where it has a URL, and then use that URL.

为什么我的脚本 src 将我指向 localhost:5000?

糖粟与秋泊 2025-01-25 03:06:08

为了获得3个通道 np.dstack

image = np.dstack([image.reshape(299,299)]*3)

或者如果您只想要一个频道

image.reshape(299,299)

In order to get 3 channels np.dstack:

image = np.dstack([image.reshape(299,299)]*3)

Or if you want only one channel

image.reshape(299,299)

无法将大小为 89401 的数组重塑为形状 (299,299,3)

糖粟与秋泊 2025-01-24 14:53:24

你可以像这样在 javascript 中进行正则表达式搜索

fetch('http://google.com')
    .then(function (response) {
        switch (response.status) {
            // status "OK"
            case 200:
                let text = response.text();
                let n = text.search("W3Schools");
                console.log(text,n)
            // status "Not Found"
            case 404:
                throw response;
        }
    })
    .then(function (template) {
        console.log(template);
    })
    .catch(function (response) {
        // "Not Found"
        console.log(response.statusText);
    });

You can do a regex search in javascript like so

fetch('http://google.com')
    .then(function (response) {
        switch (response.status) {
            // status "OK"
            case 200:
                let text = response.text();
                let n = text.search("W3Schools");
                console.log(text,n)
            // status "Not Found"
            case 404:
                throw response;
        }
    })
    .then(function (template) {
        console.log(template);
    })
    .catch(function (response) {
        // "Not Found"
        console.log(response.statusText);
    });

使用 javascript 获取网页数据并检查特定文本

糖粟与秋泊 2025-01-24 11:12:55

您可以将x,y作为cols,行索引到numpy阵列索引如下


import numpy as np

dict_xy = {'x': {0: 487.1877256317687, 1: 488.5743028961937, 2: 75.6353790613718, 3: 203.34296028880857, 4: 223.1985559566786, 5: 230.87003610108297, 6: 141.0685920577617, 7: 122.11552346570392, 8: 38.63176895306856, 9: 316.62476684835565}, 'y': {0: 38.63176895306856, 1: 84.0001478379886, 2: 51.267148014440465, 3: 73.83032490974733, 4: 79.24548736462097, 5: 115.79783393501808, 6: 169.9494584837545, 7: 153.7039711191336, 8: 128.4332129963899, 9: 127.53068592057764}}
npx, npy = np.array(list(dict_xy['x'].values())).astype(int), np.array(list(dict_xy['y'].values())).astype(int)

# test image creation
np.random.seed(42)
img = np.random.randint(0,high=256,size=(500,500,3))
#print (img)

img_select = img[npy,npx,:]

You can pass the x,y as cols, rows indexes to numpy array indexing as follows


import numpy as np

dict_xy = {'x': {0: 487.1877256317687, 1: 488.5743028961937, 2: 75.6353790613718, 3: 203.34296028880857, 4: 223.1985559566786, 5: 230.87003610108297, 6: 141.0685920577617, 7: 122.11552346570392, 8: 38.63176895306856, 9: 316.62476684835565}, 'y': {0: 38.63176895306856, 1: 84.0001478379886, 2: 51.267148014440465, 3: 73.83032490974733, 4: 79.24548736462097, 5: 115.79783393501808, 6: 169.9494584837545, 7: 153.7039711191336, 8: 128.4332129963899, 9: 127.53068592057764}}
npx, npy = np.array(list(dict_xy['x'].values())).astype(int), np.array(list(dict_xy['y'].values())).astype(int)

# test image creation
np.random.seed(42)
img = np.random.randint(0,high=256,size=(500,500,3))
#print (img)

img_select = img[npy,npx,:]

在RGB图像中查找坐标(像素)

糖粟与秋泊 2025-01-24 09:49:40

我在运行 flutter_secure_storage 时遇到了这个问题。我的 pubspec.yaml 已有四年了。我将环境移至环境:sdk:'>=3.4.0-212.0.dev <4.0.0',然后运行 ​​flutter pub get。我还生成了一个新的 index.html 和离开时的问题。

I had this problem while running flutter_secure_storage. My pubspec.yaml was four years old. I moved my environment forward to environment: sdk: '>=3.4.0-212.0.dev <4.0.0' then ran a flutter pub get. I also generated a new index.html and the problem when away.

未经手的例外:缺少Pluginexception(在Channel.example.watch上没有找到用于FlutterTowatch的方法的实现)

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文