Python Forum
How to process the array correctly - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to process the array correctly (/thread-33888.html)



How to process the array correctly - Fly_jia - Jun-07-2021

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/1LyJxMiWBkO9oah4wJWXfF2KF_W_OHuEB/view?usp=sharing
Would you help me?Thanks.


RE: How to process the array correctly - jefsummers - Jun-07-2021

The two hand written code sections are identical. Sorry, can't help.


RE: How to process the array correctly - supuflounder - Jun-07-2021

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.


RE: How to process the array correctly - Fly_jia - Jun-09-2021

(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.


RE: How to process the array correctly - Fly_jia - Jun-09-2021

(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.