小编srk*_*kdb的帖子

类型错误:eval() arg 1 必须是字符串、字节或代码对象

我正在尝试计算 x0 处的函数

f = lambda x:mu*div2d(grad2d(x))+x-b
Run Code Online (Sandbox Code Playgroud)

我试过这个:

def feval(f, *args):
    return eval(f)(*args)
feval(f,x0)
Run Code Online (Sandbox Code Playgroud)

但它会引发回溯:

Traceback (most recent call last):

  File "<ipython-input-128-6be96feb06d6>", line 1, in <module>
    feval(f,x0)

  File "<ipython-input-126-67b053764219>", line 2, in feval
    return eval(f)(*args)

TypeError: eval() arg 1 must be a string, bytes or code object
Run Code Online (Sandbox Code Playgroud)

我还读到使用 eval() 是不好的做法。那么这样做的好方法是什么?谢谢。

python eval

5
推荐指数
1
解决办法
4万
查看次数

TypeError:'tuple'对象不能解释为整数

我有x0这是一个float64(64,64)数组.每当我尝试这个:

    delta = np.random.randn(x0.shape)
Run Code Online (Sandbox Code Playgroud)

它给出了标题错误.这是如此基本,以至于我把头缠在它周围.我错过了什么?谢谢

完整的追溯如下:

Traceback (most recent call last):

  File "<ipython-input-31-dcd2365ed519>", line 1, in <module>
    delta = np.random.randn(x0.shape)

  File "mtrand.pyx", line 1420, in mtrand.RandomState.randn

  File "mtrand.pyx", line 1550, in mtrand.RandomState.standard_normal

  File "mtrand.pyx", line 167, in mtrand.cont0_array

TypeError: 'tuple' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud)

python random tuples

4
推荐指数
2
解决办法
7679
查看次数

警告:找不到入口符号Reset_Handler

错误的完整摘要如下:

Info: Internal Builder is used for build
arm-atollic-eabi-gcc -o test.elf main.o stm32f4xx_it.o system_stm32f4xx.o -T../Debug_STM32F401VC_FLASH.ld -specs=nosys.specs -static -Wl,-cref,-u,Reset_Handler -Wl,-Map=test.map -Wl,--defsym=malloc_getpagesize_P=0x80 -Wl,--start-group -lc -lm -Wl,--end-group -specs=nano.specs 
c:/program files (x86)/atollic/truestudio for stm32 9.0.1/armtools/bin/../lib/gcc/arm-atollic-eabi/6.3.1/../../../../arm-atollic-eabi/bin/ld.exe: warning: cannot find entry symbol Reset_Handler; defaulting to 08000000
main.o: In function `main':
C:\Users\Deepayan\Atollic\TrueSTUDIO\STM32_workspace_9.0\test\Debug/..\main.c:26: undefined reference to `TM_USART_Init'
C:\Users\Deepayan\Atollic\TrueSTUDIO\STM32_workspace_9.0\test\Debug/..\main.c:29: undefined reference to `TM_USART_Puts'
C:\Users\Deepayan\Atollic\TrueSTUDIO\STM32_workspace_9.0\test\Debug/..\main.c:33: undefined reference to `TM_USART_Getc'
Run Code Online (Sandbox Code Playgroud)

我们应该在哪里指定重置处理程序?谢谢。

c linker

4
推荐指数
1
解决办法
2万
查看次数

relplot seaborn 中的图例大小/标记

我一直在寻找 SO 以增加 relplot 中的图例/色调大小。

plt.rcParams["axes.labelsize"] = 20
g = sns.relplot(x='Time(days)', y='Duration Total (s)', hue='Outcome', data=t1,height=15, aspect=1, s=50);
plt.suptitle("a_10",fontsize=25, fontweight='bold')
Run Code Online (Sandbox Code Playgroud)

我似乎无法绕过它。有这么多混合引用,这有点令人困惑。

python legend scatter-plot

3
推荐指数
2
解决办法
3978
查看次数

如何在熊猫数据帧中向量化比较?

我有一部分数据框df是这样的:

| nr | Time | Event |
|----|------|-------|
| 70 | 8    |       |
| 70 | 0    |       |
| 70 | 0    |       |
| 74 | 52   |       |
| 74 | 12   |       |
| 74 | 0    |       |
Run Code Online (Sandbox Code Playgroud)

我想将事件分配到最后一列。默认情况下,第一个条目是1。

If Time[i] < 7 and nr[i] != nr[i-1], then Event[i]=Event[i-1]+1. 

If Time[i] < 7 and nr[i] = nr[i-1], then Event[i]=Event[i-1]

If Time[i] > 7 then Event[i]=Event[i-1]+1. 
Run Code Online (Sandbox Code Playgroud)

如何有效地向量化?我想避免循环。

python vectorization pandas

2
推荐指数
1
解决办法
108
查看次数

标签 统计

python ×4

c ×1

eval ×1

legend ×1

linker ×1

pandas ×1

random ×1

scatter-plot ×1

tuples ×1

vectorization ×1