Computer
Senate Leaders Ask FTC To Investigate AI Content Summaries As Anti-Competitive
Read more of this story at Slashdot.
First Neutrinos Detected At Fermilab Short-Baseline Detector
Read more of this story at Slashdot.
CodeSOD: Enumerated Science
As frequently discussed here, there are scientists who end up writing a fair bit of code, but they're not software engineers. This means that the code frequently solves the problem in front of them, it often has issues.
Nancy works in a lab with a slew of data scientists, and the code she has to handle gets… problematic.
index = 0 for index, fname in enumerate(img_list): data = np.load(img_list[index]) img = data[0][:,:] img_title 'img'+str(index).zfill(4)+'.jpg' cv2. imwrite(img_title, img) index = index + 1This code takes a bunch of image data which had been serialized out as a NumPy array (e.g., just raw data). This code reads that with np.load, then writes it back out using cv2.imwrite, converting it to an image file.
In this tight little snippet, nearly everything is wrong.
We start with an enumerate(img_list). In Python, this returns a list of tuples- an enumerator value, and the actual value. Our for loop splits that back out into an index and fname variable.
We forget the fname variable exists, and get the filename again by doing an array indexing operation (img_list[index]).
We then slice the loaded array to extract just the dimensions containing image data, and that's fine. Then we generate a filename based on the index- which, it so happens, we already HAVE a good filename that we've opted not to use (in fname). That's not a WTF, it just annoys me- my usual path for these kinds of things is to read source data from one directory and dump converted data into a different directory with the same names. That's just me.
Then, for fun, we increment index. This, fortunately, doesn't break the loop, because we're setting index at the top of the loop, and thus the increment is overwritten.
This also tells us some history of the code. It originally didn't use enumerate, and just incremented the index manually. Someone mentioned, "You should use enumerate, it's more Pythonic," and so they added the enumerate call, without understanding what about it was more Pythonic.
As scientist written code goes, I wouldn't call this the worst I've seen. It annoys me, but at least I understand it, and it wouldn't be a huge effort to clean up.
[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!Taylor Swift Endorses Kamala Harris In Response To Fake AI Trump Endorsement
Read more of this story at Slashdot.
Google Signs $10 Million Carbon Capture Deal, At $100 Per Ton of CO2
Read more of this story at Slashdot.
Alibaba Now Sells a $200,000 Diamond-Making Machine
Read more of this story at Slashdot.
Oracle Is Designing a Data Center That Would Be Powered By Three Small Nuclear Reactors
Read more of this story at Slashdot.
Former Samsung Execs Arrested For Using Stolen Tech To Build Chip Factory In China
Read more of this story at Slashdot.
Google's AI Will Help Decide Whether Unemployed Workers Get Benefits
Read more of this story at Slashdot.
Windows Update Zero-Day Being Exploited To Undo Security Fixes
Read more of this story at Slashdot.
Sony's New PS5 Heralds the End of Disc Drives
Read more of this story at Slashdot.
SpaceX Launches a Billionaire To Conduct the First Private Spacewalk
Read more of this story at Slashdot.
A Surgeon General Warning Label Must Appear on Social Media Apps, 42 State Attorneys General Demand
Read more of this story at Slashdot.
China's Huawei Shows the World Its $2,800 'Trifold' Phone
Read more of this story at Slashdot.
Malaysia's Plan To Block Overseas DNS Dies After a Day
Read more of this story at Slashdot.
Russia To Spend $646 Million To Block VPNs
Read more of this story at Slashdot.
Microsoft Performs Operations With Multiple Error-Corrected Qubits
Read more of this story at Slashdot.
Sony Unveils $700 PlayStation 5 Pro
Read more of this story at Slashdot.
A Robot Begins Removal of Melted Fuel From the Fukushima Nuclear Plant. It Could Take a Century
Read more of this story at Slashdot.
Apple Must Pay $14 Billion Tax Bill To Ireland, EU Court Rules
Read more of this story at Slashdot.