Python Forum
How to process the array correctly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to process the array correctly
#1
Photo 
import numpy as np
from timeit import default_timer as timer

mask = np.load('mask.npy', allow_pickle=True)

cell_mask_new_all = mask[:, :, :].astype(np.uint8)
cell_mask_one = cell_mask_new_all[:,:,186]

cell_mask_two = np.uint8(mask[:, :, 186])


t_1 = timer()
image_cell_mask_one = cell_mask_one*255
t_2 = timer()
print('image_cell_mask_one time:', t_2 - t_1)

t_3 = timer()
image_cell_mask_two = cell_mask_two*255
t_4 = timer()
print('image_cell_mask_two time:', t_4 - t_3)
I found a very interesting question. As you see, I use different code to get Cell_mask_one and Cell_mask_two, but the time of they multiply 255 is very difference.

I can not upload the img, and Write it out by hand。

t_1 = timer()
image_cell_mask_one = cell_mask_one*255
t_2 = timer()
print('image_cell_mask_one time:', t_2 - t_1)
0.04487754100409802

t_3 = timer()
image_cell_mask_two = cell_mask_two*255
t_4 = timer()
print('image_cell_mask_two time:', t_4 - t_3)
0.002681313009816222

The memory of data is almost 898mb,I can't upload here. I put the data at the google drive.
https://drive.google.com/file/d/1LyJxMiW...sp=sharing
Would you help me?Thanks.

Attached Files

.py   array_compare.py (Size: 480 bytes / Downloads: 271)
Reply
#2
The two hand written code sections are identical. Sorry, can't help.
Reply
#3
Are you able to print the two cell masks? That might reveal something interesting. Since you did not include all the code, it is not possible to analyze what happened. All I get is an error message that 'res' is undefined. If you want help, you must provide a complete program that can be copied and pasted into our Python environments for testing. Showing a piece of the program does not help.
Reply
#4
(Jun-07-2021, 11:10 AM)jefsummers Wrote: The two hand written code sections are identical. Sorry, can't help.
Thank you for your reply! I have revised.
Reply
#5
(Jun-07-2021, 01:11 PM)supuflounder Wrote: Are you able to print the two cell masks? That might reveal something interesting. Since you did not include all the code, it is not possible to analyze what happened. All I get is an error message that 'res' is undefined. If you want help, you must provide a complete program that can be copied and pasted into our Python environments for testing. Showing a piece of the program does not help.
Thank you for your reply! I have uploaded the code and the data, and the data is put at google drive.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,618 Sep-03-2019, 09:49 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020